blob: 69088e0d4f32a45b9a2e505c9a67d8a36b2e85aa [file] [log] [blame]
Russ Cox57eb06f2012-02-16 23:51:04 -05001// errorcheck
Russ Cox191263202010-01-25 18:23:20 -08002
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
7package main
8
9import "io"
10
11func 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 Griesemerfd897ff2011-08-19 09:31:50 -070021 case interface {
22 r()
23 w()
24 }:
Russ Cox191263202010-01-25 18:23:20 -080025 return "rw"
Ian Lance Taylord5b7c512012-01-26 23:06:47 -080026 case interface { // GCCGO_ERROR "duplicate"
Robert Griesemerfd897ff2011-08-19 09:31:50 -070027 w()
28 r()
Ian Lance Taylord5b7c512012-01-26 23:06:47 -080029 }: // GC_ERROR "duplicate"
Russ Cox191263202010-01-25 18:23:20 -080030 return "wr"
Robert Griesemerfd897ff2011-08-19 09:31:50 -070031
Russ Cox191263202010-01-25 18:23:20 -080032 }
33 return ""
34}
Robert Griesemerfd897ff2011-08-19 09:31:50 -070035
36func 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}