llgoi: Fix importing source packages together with dependent binary packages.
authorPeter Collingbourne <peter@pcc.me.uk>
Wed, 18 Mar 2015 06:04:22 +0000 (06:04 +0000)
committerPeter Collingbourne <peter@pcc.me.uk>
Wed, 18 Mar 2015 06:04:22 +0000 (06:04 +0000)
Note that this means that llgoi does not support the case
where a package's pkgpath is different from its import path,
but I don't think this should actually happen with llgoi.

Differential Revision: http://reviews.llvm.org/D8403

llvm-svn: 232612

llgo/cmd/llgoi/llgoi.go
llgo/test/llgoi/Inputs/src/bar/answer.go
llgo/test/llgoi/import-source.test
llgo/test/llgoi/import-source2.test [new file with mode: 0644]

index e8968f8..e331c31 100644 (file)
@@ -102,6 +102,9 @@ func (in *interp) makeCompilerOptions() error {
                if pkg, ok := in.inputPkgmap[pkgpath]; ok {
                        return pkg, nil
                }
+               if pkg, ok := pkgmap[pkgpath]; ok && pkg.Complete() {
+                       return pkg, nil
+               }
                return origImporter(pkgmap, pkgpath)
        }
        return nil
index 7f1bd02..202b509 100644 (file)
@@ -1,5 +1,8 @@
 package bar
 
+import "strconv"
+
 func Answer() int {
-       return 42
+       n, _ := strconv.Atoi("42")
+       return n
 }
index 22cf574..c5a3eab 100644 (file)
@@ -7,8 +7,14 @@ import "foo"
 // CHECK: # bar
 // CHECK: # foo
 
+// Test that importing binary after source works.
+import "strconv"
+
 foo.Answer()
 // CHECK: #0 int = 42
 
+strconv.FormatBool(true)
+// CHECK: #0 string = true
+
 import "foo_cgo"
 // CHECK: foo_cgo: cannot load cgo package
diff --git a/llgo/test/llgoi/import-source2.test b/llgo/test/llgoi/import-source2.test
new file mode 100644 (file)
index 0000000..fcf3b47
--- /dev/null
@@ -0,0 +1,14 @@
+// RUN: env GOPATH=%S/Inputs llgoi < %s | FileCheck %s
+
+// Test that importing binary before source works.
+import "strconv"
+
+import "foo"
+// CHECK: # bar
+// CHECK: # foo
+
+foo.Answer()
+// CHECK: #0 int = 42
+
+strconv.FormatBool(true)
+// CHECK: #0 string = true