mirror of https://github.com/golang/go.git
cmd/vet: support importing from source
Add a -source flag to cmd/vet that instructs it to typecheck purely from source code. Updates #16086 Fixes #19332 Change-Id: Ic83d0f14d5bb837a329d539b2873aeccdf7bf669 Reviewed-on: https://go-review.googlesource.com/37690 Reviewed-by: Rob Pike <r@golang.org>
This commit is contained in:
parent
7e74d43291
commit
ddbee9abd4
|
|
@ -34,6 +34,9 @@ If any flags are explicitly set to true, only those tests are run. Conversely, i
|
|||
any flag is explicitly set to false, only those tests are disabled. Thus -printf=true
|
||||
runs the printf check, -printf=false runs all checks except the printf check.
|
||||
|
||||
By default vet uses the object files generated by 'go install some/pkg' to typecheck the code.
|
||||
If the -source flag is provided, vet uses only source code.
|
||||
|
||||
Available checks:
|
||||
|
||||
Assembly declarations
|
||||
|
|
|
|||
|
|
@ -25,6 +25,7 @@ import (
|
|||
|
||||
var (
|
||||
verbose = flag.Bool("v", false, "verbose")
|
||||
source = flag.Bool("source", false, "import from source instead of compiled object files")
|
||||
tags = flag.String("tags", "", "space-separated list of build tags to apply when parsing")
|
||||
tagList = []string{} // exploded version of tags flag; set in main
|
||||
)
|
||||
|
|
|
|||
|
|
@ -61,7 +61,11 @@ func importType(path, name string) types.Type {
|
|||
|
||||
func (pkg *Package) check(fs *token.FileSet, astFiles []*ast.File) error {
|
||||
if stdImporter == nil {
|
||||
stdImporter = importer.Default()
|
||||
if *source {
|
||||
stdImporter = importer.For("source", nil)
|
||||
} else {
|
||||
stdImporter = importer.Default()
|
||||
}
|
||||
inittypes()
|
||||
}
|
||||
pkg.defs = make(map[*ast.Ident]types.Object)
|
||||
|
|
|
|||
Loading…
Reference in New Issue