Source file test/typeswitch2.go

     1  // errorcheck
     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  // Verify that various erroneous type switches are caught by the compiler.
     8  // Does not compile.
     9  
    10  package main
    11  
    12  import "io"
    13  
    14  func whatis(x interface{}) string {
    15  	switch x.(type) {
    16  	case int:
    17  		return "int"
    18  	case int: // ERROR "duplicate"
    19  		return "int8"
    20  	case io.Reader:
    21  		return "Reader1"
    22  	case io.Reader: // ERROR "duplicate"
    23  		return "Reader2"
    24  	case interface {
    25  		r()
    26  		w()
    27  	}:
    28  		return "rw"
    29  	case interface {	// ERROR "duplicate"
    30  		w()
    31  		r()
    32  	}:
    33  		return "wr"
    34  
    35  	}
    36  	return ""
    37  }
    38  

View as plain text