Russ Cox | 0b477ef | 2012-02-16 23:48:57 -0500 | [diff] [blame] | 1 | // errorcheck |
Russ Cox | 5438be4 | 2009-09-08 23:16:19 -0700 | [diff] [blame] | 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 | |
Rob Pike | fc0dc04 | 2012-02-19 13:19:43 +1100 | [diff] [blame] | 7 | // Test that incorrect uses of the blank identifer are caught. |
| 8 | // Does not compile. |
| 9 | |
Russ Cox | 5438be4 | 2009-09-08 23:16:19 -0700 | [diff] [blame] | 10 | package _ // ERROR "invalid package name _" |
| 11 | |
Daniel Morsing | b65acae | 2013-03-04 17:01:42 +0100 | [diff] [blame] | 12 | var t struct { |
| 13 | _ int |
| 14 | } |
| 15 | |
Håvard Haugen | 8a34cf7 | 2015-11-15 23:32:30 +0100 | [diff] [blame] | 16 | func (x int) _() { // ERROR "cannot define new methods on non-local type" |
| 17 | println(x) |
| 18 | } |
| 19 | |
Rémy Oudompheng | 428ea68 | 2013-07-02 09:08:43 +0200 | [diff] [blame] | 20 | type T struct { |
| 21 | _ []int |
| 22 | } |
| 23 | |
Russ Cox | 5438be4 | 2009-09-08 23:16:19 -0700 | [diff] [blame] | 24 | func main() { |
Rob Pike | 4f61fc9 | 2010-09-04 10:36:13 +1000 | [diff] [blame] | 25 | _() // ERROR "cannot use _ as value" |
| 26 | x := _+1 // ERROR "cannot use _ as value" |
Ian Lance Taylor | 387e7c2 | 2012-01-22 11:50:45 -0800 | [diff] [blame] | 27 | _ = x |
Ian Lance Taylor | 4da408f | 2013-09-28 15:19:05 -0700 | [diff] [blame] | 28 | _ = t._ // ERROR "cannot refer to blank field|invalid use of" |
Rémy Oudompheng | 428ea68 | 2013-07-02 09:08:43 +0200 | [diff] [blame] | 29 | |
| 30 | var v1, v2 T |
| 31 | _ = v1 == v2 // ERROR "cannot be compared|non-comparable" |
Russ Cox | 5438be4 | 2009-09-08 23:16:19 -0700 | [diff] [blame] | 32 | } |