From 6877ee1e07d82896becc2f624ef314613d3df4a0 Mon Sep 17 00:00:00 2001 From: Robert Griesemer Date: Tue, 10 Nov 2020 13:28:17 -0800 Subject: [PATCH] [dev.typeparams] cmd/compile: use existing findpkg algorithm when importing through types2 Change-Id: I9044de7829d22addb5bc570401508082e3f007eb Reviewed-on: https://go-review.googlesource.com/c/go/+/269057 Trust: Robert Griesemer Run-TryBot: Robert Griesemer TryBot-Result: Go Bot Reviewed-by: Ian Lance Taylor --- src/cmd/compile/internal/gc/noder.go | 7 +++++++ test/typeparam/importtest.go | 16 ++++++++++++++++ 2 files changed, 23 insertions(+) create mode 100644 test/typeparam/importtest.go diff --git a/src/cmd/compile/internal/gc/noder.go b/src/cmd/compile/internal/gc/noder.go index 14bacc14a8..4ed91035a5 100644 --- a/src/cmd/compile/internal/gc/noder.go +++ b/src/cmd/compile/internal/gc/noder.go @@ -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 index 0000000000..9cb30e8a7c --- /dev/null +++ b/test/typeparam/importtest.go @@ -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)) +} -- 2.50.0