-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
go/analysis/passes/copylock: suppress error in ill-typed code
The copylock analyzer is marked RunDespiteErrors. In ill-typed code such as S{T} where S and T are both types, the compiler will warn that T is not an expression; the copylocks analyzer should not additionally report a diagnostic as if T had been an expression of type T. The fix feels rather ad hoc. In general, analyzers marked RunDespiteErrors are unlikely to be able to anticipate the myriad ways that trees can be ill-formed and avoid spurious diagnostics. Also, add a main.go file for copylock. Fixes golang/go#67787 Change-Id: I07afbed16a4138fe602c22ec42171b4a5e634286 Reviewed-on: https://go-review.googlesource.com/c/tools/+/589895 LUCI-TryBot-Result: Go LUCI <[email protected]> Reviewed-by: Robert Findley <[email protected]>
- Loading branch information
Showing
4 changed files
with
29 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
// Copyright 2024 The Go Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style | ||
// license that can be found in the LICENSE file. | ||
|
||
//go:build ignore | ||
|
||
// The copylock command applies the golang.org/x/tools/go/analysis/passes/copylock | ||
// analysis to the specified packages of Go source code. | ||
package main | ||
|
||
import ( | ||
"golang.org/x/tools/go/analysis/passes/copylock" | ||
"golang.org/x/tools/go/analysis/singlechecker" | ||
) | ||
|
||
func main() { singlechecker.Main(copylock.Analyzer) } |
8 changes: 8 additions & 0 deletions
8
go/analysis/passes/copylock/testdata/src/issue67787/issue67787.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package issue67787 | ||
|
||
import "sync" | ||
|
||
type T struct{ mu sync.Mutex } | ||
type T1 struct{ t *T } | ||
|
||
func NewT1() *T1 { return &T1{T} } // no analyzer diagnostic about T |