cl: TestImport/TestVarOf

This commit is contained in:
xushiwei
2024-04-26 05:39:15 +08:00
parent 815a8a74fc
commit 2c3e1d1055
2 changed files with 29 additions and 1 deletions

View File

@@ -17,7 +17,11 @@
package cl package cl
import ( import (
"go/types"
"testing" "testing"
llssa "github.com/goplus/llgo/ssa"
"golang.org/x/tools/go/ssa"
) )
func TestIgnoreName(t *testing.T) { func TestIgnoreName(t *testing.T) {
@@ -25,3 +29,27 @@ func TestIgnoreName(t *testing.T) {
t.Fatal("ignoreName failed") t.Fatal("ignoreName failed")
} }
} }
func TestImport(t *testing.T) {
var ctx context
pkg := types.NewPackage("foo", "foo")
ctx.importPkg(pkg)
}
func TestVarOf(t *testing.T) {
defer func() {
if r := recover(); r == nil {
t.Fatal("varOf: no error?")
}
}()
prog := llssa.NewProgram(nil)
pkg := prog.NewPackage("foo", "foo")
pkgTypes := types.NewPackage("foo", "foo")
ctx := &context{
pkg: pkg,
goTyps: pkgTypes,
}
ssaPkg := &ssa.Package{Pkg: pkgTypes}
g := &ssa.Global{Pkg: ssaPkg}
ctx.varOf(g)
}

View File

@@ -182,7 +182,7 @@ func (p *context) compileFunc(pkg llssa.Package, pkgTypes *types.Package, f *ssa
return return
} }
if debugInstr { if debugInstr {
log.Println("==> NewFunc", f.Name(), name, "type:", sig.Recv(), sig) log.Println("==> NewFunc", name, "type:", sig.Recv(), sig)
} }
fn := pkg.NewFunc(name, sig) fn := pkg.NewFunc(name, sig)
p.inits = append(p.inits, func() { p.inits = append(p.inits, func() {