mirror of
https://github.com/golang/go
synced 2024-11-19 00:14:39 -07:00
go/loader: issue informative error (not panic) if cgo used in ad hoc package
See https://github.com/golang/go/issues/11627. Change-Id: I458bc4ea54d0db34f3ba96060d284eda4bad7111 Reviewed-on: https://go-review.googlesource.com/12190 Reviewed-by: David Crawshaw <crawshaw@golang.org>
This commit is contained in:
parent
ea5101579e
commit
c5ca59aab8
@ -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) Import(path string) { conf.addImport(path, false) }
|
||||||
|
|
||||||
func (conf *Config) addImport(path string, tests bool) {
|
func (conf *Config) addImport(path string, tests bool) {
|
||||||
if path == "unsafe" {
|
if path == "C" || path == "unsafe" {
|
||||||
return // ignore; not a real package
|
return // ignore; not a real package
|
||||||
}
|
}
|
||||||
if conf.ImportPkgs == nil {
|
if conf.ImportPkgs == nil {
|
||||||
@ -708,6 +708,13 @@ func (imp *importer) doImport(from *PackageInfo, to string) (*types.Package, err
|
|||||||
if to == "unsafe" {
|
if to == "unsafe" {
|
||||||
return types.Unsafe, nil
|
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()
|
imp.importedMu.Lock()
|
||||||
ii := imp.imported[to]
|
ii := imp.imported[to]
|
||||||
|
Loading…
Reference in New Issue
Block a user