1
0
mirror of https://github.com/golang/go synced 2024-11-18 14:04:45 -07:00

go/types: make import check optional via a flag in types.Config

It is sometimes useful for API clients to be able to disable the unused
import check, although for good reason this should not be exposed as part of
a user-facing interface. There are at least two use cases that I am aware of:

1) It allows for automated test case reduction tools such as delta or C-Reduce
   to be more easily applied to type checker input. Disabling the check
   makes it possible for the tool to identify and remove code that depends
   on imported packages without any specific knowledge of Go, as the import
   need not be removed simultaneously with the code.

2) Interactive tools (such as REPLs) that may have previously received a
   list of imports and subsequently receive a line of code that may use any
   number of these imports. It is simpler for such tools to import all the
   packages in its list than to try to identify the correct set of imports.

Change-Id: I00091a4e5c8e1bd664efd82a636f255eaaa5a2db
Reviewed-on: https://go-review.googlesource.com/2136
Reviewed-by: Robert Griesemer <gri@golang.org>
This commit is contained in:
Peter Collingbourne 2014-12-28 08:35:52 -08:00 committed by Robert Griesemer
parent 6370cd3a8e
commit bcd5efa0ef
2 changed files with 7 additions and 1 deletions

View File

@ -113,6 +113,10 @@ type Config struct {
// If Sizes != nil, it provides the sizing functions for package unsafe.
// Otherwise &StdSizes{WordSize: 8, MaxAlign: 8} is used instead.
Sizes Sizes
// If DisableUnusedImportCheck is set, packages are not checked
// for unused imports.
DisableUnusedImportCheck bool
}
// DefaultImport is the default importer invoked if Config.Import == nil.

View File

@ -233,7 +233,9 @@ func (check *Checker) Files(files []*ast.File) (err error) {
check.initOrder()
check.unusedImports()
if !check.conf.DisableUnusedImportCheck {
check.unusedImports()
}
// perform delayed checks
for _, f := range check.delayed {