Russ Cox | 57eb06f | 2012-02-16 23:51:04 -0500 | [diff] [blame] | 1 | // errorcheck |
Russ Cox | 76da278 | 2010-06-12 11:17:24 -0700 | [diff] [blame] | 2 | |
| 3 | // Copyright 2010 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 | 80a9783 | 2012-02-24 11:48:19 +1100 | [diff] [blame] | 7 | // Test line numbers in error messages. |
| 8 | // Does not compile. |
Russ Cox | 76da278 | 2010-06-12 11:17:24 -0700 | [diff] [blame] | 9 | |
| 10 | package main |
| 11 | |
| 12 | var ( |
Ian Lance Taylor | d1b434b | 2010-09-10 12:44:37 -0700 | [diff] [blame] | 13 | _ = x // ERROR "undefined.*x" |
| 14 | _ = x // ERROR "undefined.*x" |
| 15 | _ = x // ERROR "undefined.*x" |
Russ Cox | 76da278 | 2010-06-12 11:17:24 -0700 | [diff] [blame] | 16 | ) |
| 17 | |
| 18 | type T struct { |
| 19 | y int |
| 20 | } |
| 21 | |
| 22 | func foo() *T { return &T{y: 99} } |
Ian Lance Taylor | d1b434b | 2010-09-10 12:44:37 -0700 | [diff] [blame] | 23 | func bar() int { return y } // ERROR "undefined.*y" |
Russ Cox | 76da278 | 2010-06-12 11:17:24 -0700 | [diff] [blame] | 24 | |
| 25 | type T1 struct { |
| 26 | y1 int |
| 27 | } |
| 28 | |
| 29 | func foo1() *T1 { return &T1{y1: 99} } |
| 30 | var y1 = 2 |
| 31 | func bar1() int { return y1 } |
| 32 | |
| 33 | func f1(val interface{}) { |
| 34 | switch v := val.(type) { |
| 35 | default: |
| 36 | println(v) |
| 37 | } |
| 38 | } |
| 39 | |
| 40 | func f2(val interface{}) { |
| 41 | switch val.(type) { |
| 42 | default: |
Ian Lance Taylor | d1b434b | 2010-09-10 12:44:37 -0700 | [diff] [blame] | 43 | println(v) // ERROR "undefined.*v" |
Russ Cox | 76da278 | 2010-06-12 11:17:24 -0700 | [diff] [blame] | 44 | } |
| 45 | } |