diff options
author | Alan Donovan <adonovan@google.com> | 2014-11-17 15:24:12 -0500 |
---|---|---|
committer | Alan Donovan <adonovan@google.com> | 2014-11-17 15:24:12 -0500 |
commit | 0088b7ecd7687e8eeb7a30e4a3a491ef55f87d42 (patch) | |
tree | 7126e1dff2dbba17b4e1ab90eedc18e4422ea354 /go | |
parent | 89c9513804940b8e6054380737c2c345db5b86b2 (diff) | |
download | tools-0088b7ecd7687e8eeb7a30e4a3a491ef55f87d42.tar.gz |
go/types: don't panic if DefaultImport==nil, until we actually use it.
LGTM=gri
R=gri
CC=golang-codereviews
https://golang.org/cl/178860044
Diffstat (limited to 'go')
-rw-r--r-- | go/types/resolver.go | 10 | ||||
-rw-r--r-- | go/types/typeutil/example_test.go | 2 |
2 files changed, 7 insertions, 5 deletions
diff --git a/go/types/resolver.go b/go/types/resolver.go index e8b2823..7eb18a2 100644 --- a/go/types/resolver.go +++ b/go/types/resolver.go @@ -130,10 +130,14 @@ func (check *Checker) collectObjects() { importer := check.conf.Import if importer == nil { - if DefaultImport == nil { - panic(`no Config.Import or DefaultImport (missing import _ "golang.org/x/tools/go/gcimporter"?)`) + if DefaultImport != nil { + importer = DefaultImport + } else { + // Panic if we encounter an import. + importer = func(map[string]*Package, string) (*Package, error) { + panic(`no Config.Import or DefaultImport (missing import _ "golang.org/x/tools/go/gcimporter"?)`) + } } - importer = DefaultImport } // pkgImports is the set of packages already imported by any package file seen diff --git a/go/types/typeutil/example_test.go b/go/types/typeutil/example_test.go index 6fe9279..67ee34f 100644 --- a/go/types/typeutil/example_test.go +++ b/go/types/typeutil/example_test.go @@ -10,8 +10,6 @@ import ( "golang.org/x/tools/go/types" "golang.org/x/tools/go/types/typeutil" - - _ "golang.org/x/tools/go/gcimporter" // no imports; why is this necessary? ) func ExampleMap() { |