1// errorcheck
2
3// Copyright 2009 The Go Authors. All rights reserved.
4// Use of this source code is governed by a BSD-style
5// license that can be found in the LICENSE file.
6
7// Verify simple assignment errors are caught by the compiler.
8// Does not compile.
9
10package main
11
12import "sync"
13
14type T struct {
15	int
16	sync.Mutex
17}
18
19func main() {
20	{
21		var x, y sync.Mutex
22		x = y // ok
23		_ = x
24	}
25	{
26		var x, y T
27		x = y // ok
28		_ = x
29	}
30	{
31		var x, y [2]sync.Mutex
32		x = y // ok
33		_ = x
34	}
35	{
36		var x, y [2]T
37		x = y // ok
38		_ = x
39	}
40	{
41		x := sync.Mutex{0, 0} // ERROR "assignment.*Mutex"
42		_ = x
43	}
44	{
45		x := sync.Mutex{key: 0} // ERROR "(unknown|assignment).*Mutex"
46		_ = x
47	}
48	{
49		x := &sync.Mutex{} // ok
50		var y sync.Mutex   // ok
51		y = *x             // ok
52		*x = y             // ok
53		_ = x
54		_ = y
55	}
56}
57