...

Source file src/internal/types/testdata/fixedbugs/issue48008.go

Documentation: internal/types/testdata/fixedbugs

     1  // Copyright 2021 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  type T[P any] struct{}
     8  
     9  func _(x interface{}) {
    10  	switch x.(type) {
    11  	case nil:
    12  	case int:
    13  
    14  	case T[int]:
    15  	case []T[int]:
    16  	case [10]T[int]:
    17  	case struct{T[int]}:
    18  	case *T[int]:
    19  	case func(T[int]):
    20  	case interface{m(T[int])}:
    21  	case map[T[int]] string:
    22  	case chan T[int]:
    23  
    24  	case T /* ERROR "cannot use generic type T[P any] without instantiation" */ :
    25  	case []T /* ERROR "cannot use generic type" */ :
    26  	case [10]T /* ERROR "cannot use generic type" */ :
    27  	case struct{T /* ERROR "cannot use generic type" */ }:
    28  	case *T /* ERROR "cannot use generic type" */ :
    29  	case func(T /* ERROR "cannot use generic type" */ ):
    30  	case interface{m(T /* ERROR "cannot use generic type" */ )}:
    31  	case map[T /* ERROR "cannot use generic type" */ ] string:
    32  	case chan T /* ERROR "cannot use generic type" */ :
    33  
    34  	case T /* ERROR "cannot use generic type" */ , *T /* ERROR "cannot use generic type" */ :
    35  	}
    36  }
    37  
    38  // Make sure a parenthesized nil is ok.
    39  
    40  func _(x interface{}) {
    41  	switch x.(type) {
    42  	case ((nil)), int:
    43  	}
    44  }
    45  
    46  // Make sure we look for the predeclared nil.
    47  
    48  func _(x interface{}) {
    49  	type nil int
    50  	switch x.(type) {
    51  	case nil: // ok - this is the type nil
    52  	}
    53  }
    54  
    55  func _(x interface{}) {
    56  	var nil int
    57  	switch x.(type) {
    58  	case nil /* ERROR "not a type" */ : // not ok - this is the variable nil
    59  	}
    60  }
    61  

View as plain text