aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlan Donovan <adonovan@google.com>2015-09-01 22:25:16 +0000
committerandroid-build-merger <android-build-merger@google.com>2015-09-01 22:25:16 +0000
commit4b6191103c1f4a4932e902cb0ca66b14abe87e97 (patch)
treec671e9f6eb244da6b564708b8b2d5624c5b5403e
parente255979df6a545a493cce00dd2fee3d05f4d5b94 (diff)
parentc5ca59aab8c27791ce3f820caad760cff360cfc8 (diff)
downloadtools-4b6191103c1f4a4932e902cb0ca66b14abe87e97.tar.gz
go/loader: issue informative error (not panic) if cgo used in ad hoc package
automerge: c5ca59a * commit 'c5ca59aab8c27791ce3f820caad760cff360cfc8': go/loader: issue informative error (not panic) if cgo used in ad hoc package
-rw-r--r--go/loader/loader.go9
1 files changed, 8 insertions, 1 deletions
diff --git a/go/loader/loader.go b/go/loader/loader.go
index 4503dd9..5555faa 100644
--- a/go/loader/loader.go
+++ b/go/loader/loader.go
@@ -294,7 +294,7 @@ func (conf *Config) ImportWithTests(path string) { conf.addImport(path, true) }
func (conf *Config) Import(path string) { conf.addImport(path, false) }
func (conf *Config) addImport(path string, tests bool) {
- if path == "unsafe" {
+ if path == "C" || path == "unsafe" {
return // ignore; not a real package
}
if conf.ImportPkgs == nil {
@@ -708,6 +708,13 @@ func (imp *importer) doImport(from *PackageInfo, to string) (*types.Package, err
if to == "unsafe" {
return types.Unsafe, nil
}
+ if to == "C" {
+ // This should be unreachable, but ad hoc packages are
+ // not currently subject to cgo preprocessing.
+ // See https://github.com/golang/go/issues/11627.
+ return nil, fmt.Errorf(`the loader doesn't cgo-process ad hoc packages like %q; see Go issue 11627`,
+ from.Pkg.Path())
+ }
imp.importedMu.Lock()
ii := imp.imported[to]