Skip to content

Commit 773504a

Browse files
committed
go/importer: don't return packages that are not fully type-checked
Fixes #20837. Change-Id: I266519c26c8849da267b77e11abe7734d8275112 Reviewed-on: https://go-review.googlesource.com/47074 Reviewed-by: Matthew Dempsky <[email protected]>
1 parent 9745e88 commit 773504a

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

src/go/internal/srcimporter/srcimporter.go

+5-2
Original file line numberDiff line numberDiff line change
@@ -136,8 +136,11 @@ func (p *Importer) ImportFrom(path, srcDir string, mode types.ImportMode) (*type
136136
}
137137
pkg, err = conf.Check(bp.ImportPath, p.fset, files, nil)
138138
if err != nil {
139-
// return (possibly nil or incomplete) package with error (see #16088)
140-
return pkg, fmt.Errorf("type-checking package %q failed (%v)", bp.ImportPath, err)
139+
// Type-checking stops after the first error (types.Config.Error is not set),
140+
// so the returned package is very likely incomplete. Don't return it since
141+
// we don't know its condition: It's very likely unsafe to use and it's also
142+
// not added to p.packages which may cause further problems (issue #20837).
143+
return nil, fmt.Errorf("type-checking package %q failed (%v)", bp.ImportPath, err)
141144
}
142145

143146
p.packages[bp.ImportPath] = pkg

0 commit comments

Comments
 (0)