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>
diff --git a/go/analysis/analysistest/analysistest.go b/go/analysis/analysistest/analysistest.go
index 25062c6..ad979c1 100644
--- a/go/analysis/analysistest/analysistest.go
+++ b/go/analysis/analysistest/analysistest.go
@@ -263,6 +263,9 @@
 
 	// Check the facts match expectations.
 	// 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
 	for obj := range facts {
 		objects = append(objects, obj)
diff --git a/go/analysis/passes/copylock/copylock.go b/go/analysis/passes/copylock/copylock.go
index e684cd3..c199c2e 100644
--- a/go/analysis/passes/copylock/copylock.go
+++ b/go/analysis/passes/copylock/copylock.go
@@ -258,6 +258,15 @@
 		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()
 	for i := 0; i < nfields; i++ {
 		ftyp := styp.Field(i).Type()
diff --git a/go/analysis/passes/copylock/copylock_test.go b/go/analysis/passes/copylock/copylock_test.go
index 3e4ca12..acbdb52 100644
--- a/go/analysis/passes/copylock/copylock_test.go
+++ b/go/analysis/passes/copylock/copylock_test.go
@@ -7,7 +7,7 @@
 	"golang.org/x/tools/go/analysis/passes/copylock"
 )
 
-func TestFromFileSystem(t *testing.T) {
+func Test(t *testing.T) {
 	testdata := analysistest.TestData()
 	analysistest.Run(t, testdata, copylock.Analyzer, "a")
 }