Debian Codegraph @

gcc/testsuite/go.test/test/assign.go

raw
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
10 package main
11
12 import "sync"
13
14 type T struct {
15 int
16 sync.Mutex
17 }
18
19 func 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 var x = 1
58 {
59 x, x := 2, 3 // ERROR ".*x.* repeated on left side of :="
60 _ = x
61 }
62 _ = x
63 }
64 {
65 a, a := 1, 2 // ERROR ".*a.* repeated on left side of :="
66 _ = a
67 }
68 }