mirror of
https://github.com/nspcc-dev/neo-go.git
synced 2024-11-26 09:42:22 +00:00
compiler: fix bug in codegen
Main function (as far as the others uncknown to codegen at the moment of `convertFuncDecl`) didn't have package set. Fixed.
This commit is contained in:
parent
c3431f4fff
commit
c3a0998cae
1 changed files with 5 additions and 4 deletions
|
@ -272,7 +272,7 @@ func (c *codegen) convertGlobals(f ast.Node) {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *codegen) convertFuncDecl(file ast.Node, decl *ast.FuncDecl) {
|
func (c *codegen) convertFuncDecl(file ast.Node, decl *ast.FuncDecl, pkg *types.Package) {
|
||||||
var (
|
var (
|
||||||
f *funcScope
|
f *funcScope
|
||||||
ok, isLambda bool
|
ok, isLambda bool
|
||||||
|
@ -290,6 +290,7 @@ func (c *codegen) convertFuncDecl(file ast.Node, decl *ast.FuncDecl) {
|
||||||
c.setLabel(f.label)
|
c.setLabel(f.label)
|
||||||
} else {
|
} else {
|
||||||
f = c.newFunc(decl)
|
f = c.newFunc(decl)
|
||||||
|
f.pkg = pkg
|
||||||
}
|
}
|
||||||
|
|
||||||
f.rng.Start = uint16(c.prog.Len())
|
f.rng.Start = uint16(c.prog.Len())
|
||||||
|
@ -348,7 +349,7 @@ func (c *codegen) convertFuncDecl(file ast.Node, decl *ast.FuncDecl) {
|
||||||
|
|
||||||
if !isLambda {
|
if !isLambda {
|
||||||
for _, f := range c.lambda {
|
for _, f := range c.lambda {
|
||||||
c.convertFuncDecl(file, f.decl)
|
c.convertFuncDecl(file, f.decl, pkg)
|
||||||
}
|
}
|
||||||
c.lambda = make(map[string]*funcScope)
|
c.lambda = make(map[string]*funcScope)
|
||||||
}
|
}
|
||||||
|
@ -1433,7 +1434,7 @@ func (c *codegen) compile(info *buildInfo, pkg *loader.PackageInfo) error {
|
||||||
c.traverseGlobals(mainFile)
|
c.traverseGlobals(mainFile)
|
||||||
|
|
||||||
// convert the entry point first.
|
// convert the entry point first.
|
||||||
c.convertFuncDecl(mainFile, main)
|
c.convertFuncDecl(mainFile, main, pkg.Pkg)
|
||||||
|
|
||||||
// sort map keys to generate code deterministically.
|
// sort map keys to generate code deterministically.
|
||||||
keys := make([]*types.Package, 0, len(info.program.AllPackages))
|
keys := make([]*types.Package, 0, len(info.program.AllPackages))
|
||||||
|
@ -1454,7 +1455,7 @@ func (c *codegen) compile(info *buildInfo, pkg *loader.PackageInfo) error {
|
||||||
// Don't convert the function if it's not used. This will save a lot
|
// Don't convert the function if it's not used. This will save a lot
|
||||||
// of bytecode space.
|
// of bytecode space.
|
||||||
if n.Name.Name != mainIdent && funUsage.funcUsed(n.Name.Name) {
|
if n.Name.Name != mainIdent && funUsage.funcUsed(n.Name.Name) {
|
||||||
c.convertFuncDecl(f, n)
|
c.convertFuncDecl(f, n, k)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue