From 0088b7ecd7687e8eeb7a30e4a3a491ef55f87d42 Mon Sep 17 00:00:00 2001 From: Alan Donovan Date: Mon, 17 Nov 2014 15:24:12 -0500 Subject: [PATCH] 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 --- go/types/resolver.go | 10 +++++++--- 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 e8b28235..7eb18a2e 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 6fe9279a..67ee34f7 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() {