blob: 6611f8ce3ef17a41721adb12356a7dfba2077f7e [file] [log] [blame]
Russ Cox0b477ef2012-02-16 23:48:57 -05001// errorcheck
Russ Cox8b6b3802009-05-21 14:06:24 -07002
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
Rob Pikefc0dc042012-02-19 13:19:43 +11007// Verify simple assignment errors are caught by the compiler.
8// Does not compile.
9
Russ Cox8b6b3802009-05-21 14:06:24 -070010package main
11
12import "sync"
13
14type T struct {
Rob Pike4f61fc92010-09-04 10:36:13 +100015 int
16 sync.Mutex
Russ Cox8b6b3802009-05-21 14:06:24 -070017}
18
19func main() {
20 {
Rob Pike4f61fc92010-09-04 10:36:13 +100021 var x, y sync.Mutex
Russ Coxd03611f2011-11-15 12:20:59 -050022 x = y // ok
Rob Pike4f61fc92010-09-04 10:36:13 +100023 _ = x
Russ Cox8b6b3802009-05-21 14:06:24 -070024 }
25 {
Rob Pike4f61fc92010-09-04 10:36:13 +100026 var x, y T
Russ Coxd03611f2011-11-15 12:20:59 -050027 x = y // ok
Rob Pike4f61fc92010-09-04 10:36:13 +100028 _ = x
Russ Cox8b6b3802009-05-21 14:06:24 -070029 }
30 {
Rob Pike4f61fc92010-09-04 10:36:13 +100031 var x, y [2]sync.Mutex
Russ Coxd03611f2011-11-15 12:20:59 -050032 x = y // ok
Rob Pike4f61fc92010-09-04 10:36:13 +100033 _ = x
Russ Cox8b6b3802009-05-21 14:06:24 -070034 }
35 {
Rob Pike4f61fc92010-09-04 10:36:13 +100036 var x, y [2]T
Russ Coxd03611f2011-11-15 12:20:59 -050037 x = y // ok
Rob Pike4f61fc92010-09-04 10:36:13 +100038 _ = x
Russ Cox8b6b3802009-05-21 14:06:24 -070039 }
Russ Coxa3382312009-11-15 12:57:09 -080040 {
Russ Coxd03611f2011-11-15 12:20:59 -050041 x := sync.Mutex{0, 0} // ERROR "assignment.*Mutex"
Rob Pike4f61fc92010-09-04 10:36:13 +100042 _ = x
Russ Coxa3382312009-11-15 12:57:09 -080043 }
44 {
Russ Coxd03611f2011-11-15 12:20:59 -050045 x := sync.Mutex{key: 0} // ERROR "(unknown|assignment).*Mutex"
Rob Pike4f61fc92010-09-04 10:36:13 +100046 _ = x
Russ Coxa3382312009-11-15 12:57:09 -080047 }
Russ Cox9da66662009-12-03 22:09:58 -080048 {
Russ Coxd03611f2011-11-15 12:20:59 -050049 x := &sync.Mutex{} // ok
50 var y sync.Mutex // ok
51 y = *x // ok
52 *x = y // ok
Rob Pike4f61fc92010-09-04 10:36:13 +100053 _ = x
54 _ = y
Russ Coxd03611f2011-11-15 12:20:59 -050055 }
Evan Kroske55df81d2014-10-06 17:16:39 -040056 {
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 }
Russ Cox8b6b3802009-05-21 14:06:24 -070068}