Debian Codegraph @

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 (
13 "sync"
14 "time"
15 )
16
17 type T struct {
18 int
19 sync.Mutex
20 }
21
22 func main() {
23 {
24 var x, y sync.Mutex
25 x = y // ok
26 _ = x
27 }
28 {
29 var x, y T
30 x = y // ok
31 _ = x
32 }
33 {
34 var x, y [2]sync.Mutex
35 x = y // ok
36 _ = x
37 }
38 {
39 var x, y [2]T
40 x = y // ok
41 _ = x
42 }
43 {
44 x := time.Time{0, 0, nil} // ERROR "assignment.*Time"
45 _ = x
46 }
47 {
48 x := sync.Mutex{key: 0} // ERROR "(unknown|assignment).*Mutex"
49 _ = x
50 }
51 {
52 x := &sync.Mutex{} // ok
53 var y sync.Mutex // ok
54 y = *x // ok
55 *x = y // ok
56 _ = x
57 _ = y
58 }
59 {
60 var x = 1
61 {
62 x, x := 2, 3 // ERROR ".*x.* repeated on left side of :=|x redeclared in this block"
63 _ = x
64 }
65 _ = x
66 }
67 {
68 a, a := 1, 2 // ERROR ".*a.* repeated on left side of :=|a redeclared in this block"
69 _ = a
70 }
71 }