Russ Cox | 57eb06f | 2012-02-16 23:51:04 -0500 | [diff] [blame] | 1 | // errorcheck |
Russ Cox | 19126320 | 2010-01-25 18:23:20 -0800 | [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 | |
| 7 | package main |
| 8 | |
| 9 | import "io" |
| 10 | |
| 11 | func whatis(x interface{}) string { |
| 12 | switch x.(type) { |
| 13 | case int: |
| 14 | return "int" |
| 15 | case int: // ERROR "duplicate" |
| 16 | return "int8" |
| 17 | case io.Reader: |
| 18 | return "Reader1" |
| 19 | case io.Reader: // ERROR "duplicate" |
| 20 | return "Reader2" |
Robert Griesemer | fd897ff | 2011-08-19 09:31:50 -0700 | [diff] [blame] | 21 | case interface { |
| 22 | r() |
| 23 | w() |
| 24 | }: |
Russ Cox | 19126320 | 2010-01-25 18:23:20 -0800 | [diff] [blame] | 25 | return "rw" |
Ian Lance Taylor | d5b7c51 | 2012-01-26 23:06:47 -0800 | [diff] [blame] | 26 | case interface { // GCCGO_ERROR "duplicate" |
Robert Griesemer | fd897ff | 2011-08-19 09:31:50 -0700 | [diff] [blame] | 27 | w() |
| 28 | r() |
Ian Lance Taylor | d5b7c51 | 2012-01-26 23:06:47 -0800 | [diff] [blame] | 29 | }: // GC_ERROR "duplicate" |
Russ Cox | 19126320 | 2010-01-25 18:23:20 -0800 | [diff] [blame] | 30 | return "wr" |
Robert Griesemer | fd897ff | 2011-08-19 09:31:50 -0700 | [diff] [blame] | 31 | |
Russ Cox | 19126320 | 2010-01-25 18:23:20 -0800 | [diff] [blame] | 32 | } |
| 33 | return "" |
| 34 | } |
Robert Griesemer | fd897ff | 2011-08-19 09:31:50 -0700 | [diff] [blame] | 35 | |
| 36 | func notused(x interface{}) { |
| 37 | // The first t is in a different scope than the 2nd t; it cannot |
| 38 | // be accessed (=> declared and not used error); but it is legal |
| 39 | // to declare it. |
| 40 | switch t := 0; t := x.(type) { // ERROR "declared and not used" |
| 41 | case int: |
| 42 | _ = t // this is using the t of "t := x.(type)" |
| 43 | } |
| 44 | } |