diff --git a/cl/compile.go b/cl/compile.go index cd3acbfd..91694861 100644 --- a/cl/compile.go +++ b/cl/compile.go @@ -25,6 +25,7 @@ import ( "log" "os" "sort" + "strings" "github.com/goplus/llgo/cl/blocks" "github.com/goplus/llgo/internal/typepatch" @@ -288,9 +289,14 @@ func (p *context) compileBlock(b llssa.Builder, block *ssa.BasicBlock, n int, do instrs = instrs[:last] } else { // TODO(xsw): confirm pyMod don't need to call AfterInit - p.inits = append(p.inits, func() { + after := func() { pkg.AfterInit(b, ret) - }) + } + if strings.HasSuffix(fn.Name(), "$hasPatch") { + p.inits[len(p.inits)-1] = after + } else { + p.inits = append(p.inits, after) + } } } else if doMainInit { argc := pkg.NewVar("__llgo_argc", types.NewPointer(types.Typ[types.Int32]), llssa.InC)