github.com/go-asm/go@v1.21.1-0.20240213172139-40c5ead50c48/types/testdata/fixedbugs/issue42758.go (about)

     1  // Copyright 2020 The Go Authors. All rights reserved.
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  package p
     6  
     7  func _[T any](x interface{}){
     8  	switch x.(type) {
     9  	case T: // ok to use a type parameter
    10  	case int:
    11  	}
    12  
    13  	switch x.(type) {
    14  	case T:
    15  	case T /* ERROR "duplicate case" */ :
    16  	}
    17  }
    18  
    19  type constraint interface {
    20  	~int
    21  }
    22  
    23  func _[T constraint](x interface{}){
    24  	switch x.(type) {
    25  	case T: // ok to use a type parameter even if type set contains int
    26  	case int:
    27  	}
    28  }
    29  
    30  func _(x constraint /* ERROR "contains type constraints" */ ) {
    31  	switch x.(type) { // no need to report another error
    32  	}
    33  }