blob: bf94d1a0fb91dca76c9c91653624c614be229492 [file] [log] [blame]
Russ Cox0b477ef2012-02-16 23:48:57 -05001// errorcheck
Russ Cox5438be42009-09-08 23:16:19 -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// Test that incorrect uses of the blank identifer are caught.
8// Does not compile.
9
Russ Cox5438be42009-09-08 23:16:19 -070010package _ // ERROR "invalid package name _"
11
Daniel Morsingb65acae2013-03-04 17:01:42 +010012var t struct {
13 _ int
14}
15
Håvard Haugen8a34cf72015-11-15 23:32:30 +010016func (x int) _() { // ERROR "cannot define new methods on non-local type"
17 println(x)
18}
19
Rémy Oudompheng428ea682013-07-02 09:08:43 +020020type T struct {
21 _ []int
22}
23
Russ Cox5438be42009-09-08 23:16:19 -070024func main() {
Rob Pike4f61fc92010-09-04 10:36:13 +100025 _() // ERROR "cannot use _ as value"
26 x := _+1 // ERROR "cannot use _ as value"
Ian Lance Taylor387e7c22012-01-22 11:50:45 -080027 _ = x
Ian Lance Taylor4da408f2013-09-28 15:19:05 -070028 _ = t._ // ERROR "cannot refer to blank field|invalid use of"
Rémy Oudompheng428ea682013-07-02 09:08:43 +020029
30 var v1, v2 T
31 _ = v1 == v2 // ERROR "cannot be compared|non-comparable"
Russ Cox5438be42009-09-08 23:16:19 -070032}