go/analysis/passes/copylock: add workaround for go1.10
CL 121876 made sync.noCopy implement sync.Locker and added this as an assumption to vet. But now that copylock is no longer in the standard library it cannot assume that it is analyzing a recent standard library in which noCopy has an Unlock method. Change-Id: I5a30b3711ae6cc0855eb246fdd93b1906779bdde Reviewed-on: https://go-review.googlesource.com/c/141683 Reviewed-by: Michael Matloob <matloob@golang.org> Run-TryBot: Michael Matloob <matloob@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
This commit is contained in:
parent
cdd5f6199c
commit
8919434dde
|
@ -263,6 +263,9 @@ func check(t Testing, gopath string, pass *analysis.Pass, diagnostics []analysis
|
||||||
|
|
||||||
// Check the facts match expectations.
|
// Check the facts match expectations.
|
||||||
// Report errors in lexical order for determinism.
|
// Report errors in lexical order for determinism.
|
||||||
|
// (It's only deterministic within each file, not across files,
|
||||||
|
// because go/packages does not guarantee file.Pos is ascending
|
||||||
|
// across the files of a single compilation unit.)
|
||||||
var objects []types.Object
|
var objects []types.Object
|
||||||
for obj := range facts {
|
for obj := range facts {
|
||||||
objects = append(objects, obj)
|
objects = append(objects, obj)
|
||||||
|
|
|
@ -258,6 +258,15 @@ func lockPath(tpkg *types.Package, typ types.Type) typePath {
|
||||||
return []types.Type{typ}
|
return []types.Type{typ}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// In go1.10, sync.noCopy did not implement Locker.
|
||||||
|
// (The Unlock method was added only in CL 121876.)
|
||||||
|
// TODO(adonovan): remove workaround when we drop go1.10.
|
||||||
|
if named, ok := typ.(*types.Named); ok &&
|
||||||
|
named.Obj().Name() == "noCopy" &&
|
||||||
|
named.Obj().Pkg().Path() == "sync" {
|
||||||
|
return []types.Type{typ}
|
||||||
|
}
|
||||||
|
|
||||||
nfields := styp.NumFields()
|
nfields := styp.NumFields()
|
||||||
for i := 0; i < nfields; i++ {
|
for i := 0; i < nfields; i++ {
|
||||||
ftyp := styp.Field(i).Type()
|
ftyp := styp.Field(i).Type()
|
||||||
|
|
|
@ -7,7 +7,7 @@ import (
|
||||||
"golang.org/x/tools/go/analysis/passes/copylock"
|
"golang.org/x/tools/go/analysis/passes/copylock"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestFromFileSystem(t *testing.T) {
|
func Test(t *testing.T) {
|
||||||
testdata := analysistest.TestData()
|
testdata := analysistest.TestData()
|
||||||
analysistest.Run(t, testdata, copylock.Analyzer, "a")
|
analysistest.Run(t, testdata, copylock.Analyzer, "a")
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue