]> Cypherpunks repositories - gostls13.git/commitdiff
[dev.typeparams] cmd/compile: use existing findpkg algorithm when importing through...
authorRobert Griesemer <gri@golang.org>
Tue, 10 Nov 2020 21:28:17 +0000 (13:28 -0800)
committerRobert Griesemer <gri@golang.org>
Wed, 11 Nov 2020 01:11:43 +0000 (01:11 +0000)
Change-Id: I9044de7829d22addb5bc570401508082e3f007eb
Reviewed-on: https://go-review.googlesource.com/c/go/+/269057
Trust: Robert Griesemer <gri@golang.org>
Run-TryBot: Robert Griesemer <gri@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
src/cmd/compile/internal/gc/noder.go
test/typeparam/importtest.go [new file with mode: 0644]

index 14bacc14a8b39845683aa0baaa900d1854a28b07..4ed91035a5ad13c204aae9d5c1a9a293ac06dada 100644 (file)
@@ -95,6 +95,13 @@ func parseFiles(filenames []string, allowGenerics bool) (lines uint) {
                        },
                        Importer: &gcimports{
                                packages: make(map[string]*types2.Package),
+                               lookup: func(path string) (io.ReadCloser, error) {
+                                       file, ok := findpkg(path)
+                                       if !ok {
+                                               return nil, fmt.Errorf("can't find import: %q", path)
+                                       }
+                                       return os.Open(file)
+                               },
                        },
                }
                conf.Check(Ctxt.Pkgpath, files, nil)
diff --git a/test/typeparam/importtest.go b/test/typeparam/importtest.go
new file mode 100644 (file)
index 0000000..9cb30e8
--- /dev/null
@@ -0,0 +1,16 @@
+// compile -G
+
+// Copyright 2020 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+// This file checks that basic importing works in -G mode.
+
+package p
+
+import "fmt"
+import "math"
+
+func f(x float64) {
+       fmt.Println(math.Sin(x))
+}