compiler: compile init even if there are no globals

`init` can be useful even if no globals are present,
e.g. we can use some syscall inside.
This commit is contained in:
Evgenii Stratonikov 2020-08-05 12:59:50 +03:00
parent 439d9ff94d
commit 4488f61777
3 changed files with 51 additions and 14 deletions

View file

@ -1495,8 +1495,8 @@ func (c *codegen) compile(info *buildInfo, pkg *loader.PackageInfo) error {
// Bring all imported functions into scope.
c.ForEachFile(c.resolveFuncDecls)
n := c.traverseGlobals()
if n > 0 {
n, hasInit := c.traverseGlobals()
if n > 0 || hasInit {
emit.Opcode(c.prog.BinWriter, opcode.RET)
c.initEndOffset = c.prog.Len()
}