The analysis package defines the interface between a modular static
analysis and an analysis driver program.
-
-THIS INTERFACE IS EXPERIMENTAL AND SUBJECT TO CHANGE.
-We aim to finalize it by November 2018.
-
Background
A static analysis is a function that inspects a package of Go code and
offsets := arch.sizes.Offsetsof(fields)
elemoff := int(offsets[1])
for i := 0; i < int(tu.Len()); i++ {
- cc = appendComponentsRecursive(arch, elem, cc, suffix+"_"+strconv.Itoa(i), i*elemoff)
+ cc = appendComponentsRecursive(arch, elem, cc, suffix+"_"+strconv.Itoa(i), off+i*elemoff)
}
}
for _, fld := range list {
t := pass.TypesInfo.Types[fld.Type].Type
- // Work around github.com/golang/go/issues/28277.
+ // Work around https://golang.org/issue/28277.
if t == nil {
if ell, ok := fld.Type.(*ast.Ellipsis); ok {
t = types.NewSlice(pass.TypesInfo.Types[ell.Elt].Type)
// TODO(adonovan): this reports n(n-1)/2 errors for an
// expression e||...||e of depth n. Fix.
- // See https://github.com/golang/go/issues/28086.
+ // See https://golang.org/issue/28086.
comm := op.commutativeSets(pass.TypesInfo, e)
for _, exprs := range comm {
op.checkRedundant(pass, exprs)
*seen = map[[2]string]token.Pos{}
}
if pos, ok := (*seen)[[2]string{key, val}]; ok {
- posn := pass.Fset.Position(pos)
- posn.Filename = filepath.Base(posn.Filename)
- posn.Column = 0
- pass.Reportf(nearest.Pos(), "struct field %s repeats %s tag %q also at %s", field.Name(), key, val, posn)
+ alsoPos := pass.Fset.Position(pos)
+ alsoPos.Column = 0
+
+ // Make the "also at" position relative to the current position,
+ // to ensure that all warnings are unambiguous and correct. For
+ // example, via anonymous struct fields, it's possible for the
+ // two fields to be in different packages and directories.
+ thisPos := pass.Fset.Position(field.Pos())
+ rel, err := filepath.Rel(filepath.Dir(thisPos.Filename), alsoPos.Filename)
+ if err != nil {
+ // Possibly because the paths are relative; leave the
+ // filename alone.
+ } else {
+ alsoPos.Filename = rel
+ }
+
+ pass.Reportf(nearest.Pos(), "struct field %s repeats %s tag %q also at %s", field.Name(), key, val, alsoPos)
} else {
(*seen)[[2]string{key, val}] = field.Pos()
}
}
var importerForCompiler = func(_ *token.FileSet, compiler string, lookup importer.Lookup) types.Importer {
- // broken legacy implementation (github.com/golang/go/issues/28995)
+ // broken legacy implementation (https://golang.org/issue/28995)
return importer.For(compiler, lookup)
}