1
0
mirror of https://github.com/golang/go synced 2024-11-22 22:30:02 -07:00
go/test/assign.go
Michael Anthony Knyszek 53b2b64b64 sync: add explicit noCopy fields to Map, Mutex, and Once
Following CLs will refactor Mutex and change the internals of Map. This
ends up breaking tests in x/tools for the copylock vet check, because
the error message changes. Let's insulate ourselves from such things
permanently by adding an explicit noCopy field. We'll update the vet
check to accept that as the problem, rather than depend on less explicit
internals.

We capture Once here too to clean up the error message as well.

Change-Id: Iead985fc8ec9ef3ea5ff615f26dde17bb03aeadb
Reviewed-on: https://go-review.googlesource.com/c/go/+/627777
Reviewed-by: Cherry Mui <cherryyz@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Auto-Submit: Michael Knyszek <mknyszek@google.com>
Reviewed-by: Tim King <taking@google.com>
2024-11-18 18:52:54 +00:00

72 lines
1.0 KiB
Go

// errorcheck
// Copyright 2009 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.
// Verify simple assignment errors are caught by the compiler.
// Does not compile.
package main
import (
"sync"
"time"
)
type T struct {
int
sync.Mutex
}
func main() {
{
var x, y sync.Mutex
x = y // ok
_ = x
}
{
var x, y T
x = y // ok
_ = x
}
{
var x, y [2]sync.Mutex
x = y // ok
_ = x
}
{
var x, y [2]T
x = y // ok
_ = x
}
{
x := time.Time{0, 0, nil} // ERROR "assignment.*Time"
_ = x
}
{
x := sync.Mutex{key: 0} // ERROR "(unknown|assignment).*Mutex"
_ = x
}
{
x := &sync.Mutex{} // ok
var y sync.Mutex // ok
y = *x // ok
*x = y // ok
_ = x
_ = y
}
{
var x = 1
{
x, x := 2, 3 // ERROR ".*x.* repeated on left side of :=|x redeclared in this block"
_ = x
}
_ = x
}
{
a, a := 1, 2 // ERROR ".*a.* repeated on left side of :=|a redeclared in this block"
_ = a
}
}