]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/vet: support importing from source
authorJosh Bleecher Snyder <josharian@gmail.com>
Thu, 2 Mar 2017 17:04:03 +0000 (09:04 -0800)
committerJosh Bleecher Snyder <josharian@gmail.com>
Thu, 2 Mar 2017 18:43:23 +0000 (18:43 +0000)
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>
src/cmd/vet/doc.go
src/cmd/vet/main.go
src/cmd/vet/types.go

index 5cbe116abe134f48415bea22b60dba43fd6ce18d..1ee44a43fc300007d5e1618b4ae01013519089ba 100644 (file)
@@ -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
index 3da0b3ccf514854d27eae53d66fe3f3e93fa84a7..ec4cb727979f0ccd80254900e16fdd0e6d76169f 100644 (file)
@@ -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
 )
index f1927738c4eacb9156d53164bd8f2f15e6f4accc..3a5e71c87ca96074aa40c2738f8bf4b3505e2847 100644 (file)
@@ -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)