summaryrefslogtreecommitdiffstats
path: root/llgo
diff options
context:
space:
mode:
Diffstat (limited to 'llgo')
-rw-r--r--llgo/cmd/llgoi/llgoi.go11
-rw-r--r--llgo/irgen/compiler.go8
-rw-r--r--llgo/test/llgoi/import-source.test12
3 files changed, 21 insertions, 10 deletions
diff --git a/llgo/cmd/llgoi/llgoi.go b/llgo/cmd/llgoi/llgoi.go
index e331c316759..09d05e5de5c 100644
--- a/llgo/cmd/llgoi/llgoi.go
+++ b/llgo/cmd/llgoi/llgoi.go
@@ -76,8 +76,8 @@ type interp struct {
imports []*types.Package
scope map[string]types.Object
- pkgmap, inputPkgmap map[string]*types.Package
- pkgnum int
+ pkgmap map[string]*types.Package
+ pkgnum int
}
func (in *interp) makeCompilerOptions() error {
@@ -91,6 +91,7 @@ func (in *interp) makeCompilerOptions() error {
TargetTriple: llvm.DefaultTargetTriple(),
ImportPaths: importPaths,
GenerateDebug: true,
+ Packages: in.pkgmap,
}
err = in.copts.MakeImporter()
if err != nil {
@@ -99,9 +100,6 @@ func (in *interp) makeCompilerOptions() error {
origImporter := in.copts.Importer
in.copts.Importer = func(pkgmap map[string]*types.Package, pkgpath string) (*types.Package, error) {
- if pkg, ok := in.inputPkgmap[pkgpath]; ok {
- return pkg, nil
- }
if pkg, ok := pkgmap[pkgpath]; ok && pkg.Complete() {
return pkg, nil
}
@@ -113,7 +111,6 @@ func (in *interp) makeCompilerOptions() error {
func (in *interp) init() error {
in.scope = make(map[string]types.Object)
in.pkgmap = make(map[string]*types.Package)
- in.inputPkgmap = make(map[string]*types.Package)
err := in.makeCompilerOptions()
if err != nil {
@@ -174,7 +171,7 @@ func (in *interp) loadSourcePackage(fset *token.FileSet, files []*ast.File, pkgp
}
}()
importfunc()
- in.inputPkgmap[pkgpath] = pkg
+ in.pkgmap[pkgpath] = pkg
return
}
diff --git a/llgo/irgen/compiler.go b/llgo/irgen/compiler.go
index 36d35b78ce2..16769216a0f 100644
--- a/llgo/irgen/compiler.go
+++ b/llgo/irgen/compiler.go
@@ -102,6 +102,9 @@ type CompilerOptions struct {
// DisableUnusedImportCheck disables the unused import check performed
// by go/types if set to true.
DisableUnusedImportCheck bool
+
+ // Packages is used by go/types as the imported package map if non-nil.
+ Packages map[string]*types.Package
}
type Compiler struct {
@@ -208,8 +211,9 @@ func (compiler *compiler) compile(fset *token.FileSet, astFiles []*ast.File, imp
impcfg := &loader.Config{
Fset: fset,
TypeChecker: types.Config{
- Import: compiler.Importer,
- Sizes: compiler.llvmtypes,
+ Packages: compiler.Packages,
+ Import: compiler.Importer,
+ Sizes: compiler.llvmtypes,
DisableUnusedImportCheck: compiler.DisableUnusedImportCheck,
},
Build: &buildctx.Context,
diff --git a/llgo/test/llgoi/import-source.test b/llgo/test/llgoi/import-source.test
index c5a3eabf38d..b545b52697e 100644
--- a/llgo/test/llgoi/import-source.test
+++ b/llgo/test/llgoi/import-source.test
@@ -1,4 +1,4 @@
-// RUN: env GOPATH=%S/Inputs llgoi < %s | FileCheck %s
+// RUN: env GOPATH=%S/Inputs llgoi < %s 2>&1 | FileCheck %s
// make sure user symbols do not conflict with imported source package
Answer := 1
@@ -16,5 +16,15 @@ foo.Answer()
strconv.FormatBool(true)
// CHECK: #0 string = true
+var v1 strconv.NumError
+var v2 strconv.NumError
+
+// v1 and v2 should have the same type identity.
+// CHECK-NOT: cannot assign
+v1 = v2
+
+// Method lookup relies on v1 having a consistent type.
+v1.Error
+
import "foo_cgo"
// CHECK: foo_cgo: cannot load cgo package
OpenPOWER on IntegriCloud