blob: 54a72976b77c64a6cac7efd6fcfa21cc9e6ee1ea [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
Rémy Oudompheng428ea682013-07-02 09:08:43 +020016type T struct {
17 _ []int
18}
19
Russ Cox5438be42009-09-08 23:16:19 -070020func main() {
Rob Pike4f61fc92010-09-04 10:36:13 +100021 _() // ERROR "cannot use _ as value"
22 x := _+1 // ERROR "cannot use _ as value"
Ian Lance Taylor387e7c22012-01-22 11:50:45 -080023 _ = x
Ian Lance Taylor4da408f2013-09-28 15:19:05 -070024 _ = t._ // ERROR "cannot refer to blank field|invalid use of"
Rémy Oudompheng428ea682013-07-02 09:08:43 +020025
26 var v1, v2 T
27 _ = v1 == v2 // ERROR "cannot be compared|non-comparable"
Russ Cox5438be42009-09-08 23:16:19 -070028}