Skip to content

Commit 70b603f

Browse files
adonovangopherbot
authored andcommitted
go/importer: document limitations of this API
Arguably it should be deprecated, but that's a process. Updates #71272 Change-Id: I69de1f9709c45dfea0fe67d96a7bd15d3df4e2f1 Reviewed-on: https://go-review.googlesource.com/c/go/+/643795 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Robert Findley <rfindley@google.com> Auto-Submit: Alan Donovan <adonovan@google.com>
1 parent f6d17c5 commit 70b603f

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

‎src/go/importer/importer.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,13 @@
33
// license that can be found in the LICENSE file.
44

55
// Package importer provides access to export data importers.
6+
//
7+
// These functions, which are mostly deprecated, date from before the
8+
// introduction of modules in release Go 1.11. They should no longer
9+
// be relied on except for use in test cases using small programs that
10+
// depend only on the standard library. For reliable module-aware
11+
// loading of type information, use the packages.Load function from
12+
// golang.org/x/tools/go/packages.
613
package importer
714

815
import (
@@ -79,6 +86,12 @@ func For(compiler string, lookup Lookup) types.Importer {
7986

8087
// Default returns an Importer for the compiler that built the running binary.
8188
// If available, the result implements [types.ImporterFrom].
89+
//
90+
// Default may be convenient for use in the simplest of cases, but
91+
// most clients should instead use [ForCompiler], which accepts a
92+
// [token.FileSet] from the caller; without it, all position
93+
// information derived from the Importer will be incorrect and
94+
// misleading. See also the package documentation.
8295
func Default() types.Importer {
8396
return For(runtime.Compiler, nil)
8497
}

0 commit comments

Comments
 (0)