...

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

Documentation: internal/types/testdata/fixedbugs

     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  // Examples from the issue adjusted to match new [T any] syntax for type parameters.
     6  // Also, previously permitted empty type parameter lists and instantiations
     7  // are now syntax errors.
     8  //
     9  // The primary concern here is that these tests shouldn't crash the type checker.
    10  // The quality of the error messages is secondary as these are all pretty esoteric
    11  // or artificial test cases.
    12  
    13  package p
    14  
    15  // crash 1
    16  type nt1[_ any]interface{g /* ERROR "undefined" */ }
    17  type ph1[e nt1[e],g(d /* ERROR "undefined" */ )]s /* ERROR "undefined" */
    18  func(*ph1[e,e /* ERROR "redeclared" */ ])h(d /* ERROR "undefined" */ )
    19  
    20  // crash 2
    21  // Disabled: empty []'s are now syntax errors. This example leads to too many follow-on errors.
    22  // type Numeric2 interface{t2 /* ERROR "not a type" */ }
    23  // func t2[T Numeric2](s[]T){0 /* ERROR "not a type */ []{s /* ERROR cannot index" */ [0][0]}}
    24  
    25  // crash 3
    26  type t3 *interface{ t3.p /* ERROR "t3.p is not a type" */ }
    27  
    28  // crash 4
    29  type Numeric4 interface{t4 /* ERROR "not a type" */ }
    30  func t4[T Numeric4](s[]T){if( /* ERROR "non-boolean" */ 0){*s /* ERROR "cannot indirect" */ [0]}}
    31  
    32  // crash 7
    33  type foo7 interface { bar() }
    34  type x7[A any] struct{ foo7 }
    35  func main7() { var _ foo7 = x7[int]{} }
    36  
    37  // crash 8
    38  type foo8[A any] interface { ~A /* ERROR "cannot be a type parameter" */ }
    39  func bar8[A foo8[A]](a A) {}
    40  
    41  // crash 9
    42  type foo9[A any] interface { foo9 /* ERROR "invalid recursive type" */ [A] }
    43  func _() { var _ = new(foo9[int]) }
    44  
    45  // crash 12
    46  var u, i [func /* ERROR "used as value" */ /* ERROR "used as value" */ (u /* ERROR "u is not a type" */ /* ERROR "u is not a type" */ , c /* ERROR "undefined" */ /* ERROR "undefined" */ ) {}(0, len /* ERROR "must be called" */ /* ERROR "must be called" */ )]c /* ERROR "undefined" */ /* ERROR "undefined" */
    47  
    48  // crash 15
    49  func y15() { var a /* ERROR "declared and not used" */ interface{ p() } = G15[string]{} }
    50  type G15[X any] s /* ERROR "undefined" */
    51  func (G15 /* ERRORx `generic type .* without instantiation` */ ) p()
    52  
    53  // crash 16
    54  type Foo16[T any] r16 /* ERROR "not a type" */
    55  func r16[T any]() Foo16[Foo16[T]] { panic(0) }
    56  
    57  // crash 17
    58  type Y17 interface{ c() }
    59  type Z17 interface {
    60  	c() Y17
    61  	Y17 /* ERROR "duplicate method" */
    62  }
    63  func F17[T Z17](T) {}
    64  
    65  // crash 18
    66  type o18[T any] []func(_ o18[[]_ /* ERROR "cannot use _" */ ])
    67  
    68  // crash 19
    69  type Z19 [][[]Z19{}[0][0]]c19 /* ERROR "undefined" */
    70  
    71  // crash 20
    72  type Z20 /* ERROR "invalid recursive type" */ interface{ Z20 }
    73  func F20[t Z20]() { F20(t /* ERROR "invalid composite literal type" */ /* ERROR "too many arguments in call to F20\n\thave (unknown type)\n\twant ()" */ {}) }
    74  
    75  // crash 21
    76  type Z21 /* ERROR "invalid recursive type" */ interface{ Z21 }
    77  func F21[T Z21]() { ( /* ERROR "not used" */ F21[Z21]) }
    78  
    79  // crash 24
    80  type T24[P any] P // ERROR "cannot use a type parameter as RHS in type declaration"
    81  func (r T24[P]) m() { T24 /* ERROR "without instantiation" */ .m() }
    82  
    83  // crash 25
    84  type T25[A any] int
    85  func (t T25[A]) m1() {}
    86  var x T25 /* ERROR "without instantiation" */ .m1
    87  
    88  // crash 26
    89  type T26 = interface{ F26[ /* ERROR "interface method must have no type parameters" */ Z any]() }
    90  func F26[Z any]() T26 { return F26[] /* ERROR "operand" */ }
    91  
    92  // crash 27
    93  func e27[T any]() interface{ x27 /* ERROR "not a type" */ } { panic(0) }
    94  func x27() { e27 /* ERROR "cannot infer T" */ () }
    95  

View as plain text