-
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: test for noCopy for sync Map, Mutex, Once
Right now the copylock tests check for details on these types that are implementation details and/or have some other problem (a less useful error message, or a false negative altogether). CL 627777 modifies the sync package to attach explicit anonymous noCopy fields on each of these types. This change updates the tests to match that, which also helps with and/or resolves a couple issues with copylock captured in the test suite. Note: this change also temporarily disables a couple of the problematic tests. In the next CL we'll re-enable them, once CL 627777 lands. Change-Id: I100c71ea05b4f08595e37d0c8e81f9543abe7d74 Reviewed-on: https://go-review.googlesource.com/c/tools/+/628435 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Alan Donovan <adonovan@google.com> Reviewed-by: Tim King <taking@google.com>
- Loading branch information
Showing
4 changed files
with
55 additions
and
18 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
25 changes: 25 additions & 0 deletions
25
go/analysis/passes/copylock/testdata/src/unfortunate/local_go123.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,25 @@ | ||
// 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 !go1.24 | ||
|
||
package unfortunate | ||
|
||
import "sync" | ||
|
||
// TODO: Unfortunate cases | ||
|
||
// Non-ideal error message: | ||
// Since we're looking for Lock methods, sync.Once's underlying | ||
// sync.Mutex gets called out, but without any reference to the sync.Once. | ||
type LocalOnce sync.Once | ||
|
||
func (LocalOnce) Bad() {} // want `Bad passes lock by value: a.LocalOnce contains sync.\b.*` | ||
|
||
// False negative: | ||
// LocalMutex doesn't have a Lock method. | ||
// Nevertheless, it is probably a bad idea to pass it by value. | ||
type LocalMutex sync.Mutex | ||
|
||
func (LocalMutex) Bad() {} // WANTED: An error here :( |
19 changes: 19 additions & 0 deletions
19
go/analysis/passes/copylock/testdata/src/unfortunate/local_go124.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,19 @@ | ||
// 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 go1.24 | ||
|
||
package unfortunate | ||
|
||
import "sync" | ||
|
||
// Cases where the interior sync.noCopy shows through. | ||
|
||
type LocalOnce sync.Once | ||
|
||
func (LocalOnce) Bad() {} // want "Bad passes lock by value: a.LocalOnce contains sync.noCopy" | ||
|
||
type LocalMutex sync.Mutex | ||
|
||
func (LocalMutex) Bad() {} // want "Bad passes lock by value: a.LocalMutex contains sync.noCopy" |