github.com/go-asm/go@v1.21.1-0.20240213172139-40c5ead50c48/types/testdata/fixedbugs/issue39634.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  // Examples 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  package p
    10  
    11  // crash 1
    12  type nt1[_ any]interface{g /* ERROR "undefined" */ }
    13  type ph1[e nt1[e],g(d /* ERROR "undefined" */ )]s /* ERROR "undefined" */
    14  func(*ph1[e,e /* ERROR "redeclared" */ ])h(d /* ERROR "undefined" */ )
    15  
    16  // crash 2
    17  // Disabled: empty []'s are now syntax errors. This example leads to too many follow-on errors.
    18  // type Numeric2 interface{t2 /* ERROR "not a type" */ }
    19  // func t2[T Numeric2](s[]T){0 /* ERROR "not a type */ []{s /* ERROR cannot index" */ [0][0]}}
    20  
    21  // crash 3
    22  type t3 *interface{ t3.p /* ERROR "t3.p is not a type" */ }
    23  
    24  // crash 4
    25  type Numeric4 interface{t4 /* ERROR "not a type" */ }
    26  func t4[T Numeric4](s[]T){if( /* ERROR "non-boolean" */ 0){*s /* ERROR "cannot indirect" */ [0]}}
    27  
    28  // crash 7
    29  type foo7 interface { bar() }
    30  type x7[A any] struct{ foo7 }
    31  func main7() { var _ foo7 = x7[int]{} }
    32  
    33  // crash 8
    34  type foo8[A any] interface { ~A /* ERROR "cannot be a type parameter" */ }
    35  func bar8[A foo8[A]](a A) {}
    36  
    37  // crash 9
    38  type foo9[A any] interface { foo9 /* ERROR "invalid recursive type" */ [A] }
    39  func _() { var _ = new(foo9[int]) }
    40  
    41  // crash 12
    42  var u /* ERROR "cycle" */ , i [func /* ERROR "used as value" */ /* ERROR "used as value" */ (u, c /* ERROR "undefined" */ /* ERROR "undefined" */ ) {}(0, len /* ERROR "must be called" */ /* ERROR "must be called" */ )]c /* ERROR "undefined" */ /* ERROR "undefined" */
    43  
    44  // crash 15
    45  func y15() { var a /* ERROR "declared and not used" */ interface{ p() } = G15[string]{} }
    46  type G15[X any] s /* ERROR "undefined" */
    47  func (G15 /* ERRORx `generic type .* without instantiation` */ ) p()
    48  
    49  // crash 16
    50  type Foo16[T any] r16 /* ERROR "not a type" */
    51  func r16[T any]() Foo16[Foo16[T]] { panic(0) }
    52  
    53  // crash 17
    54  type Y17 interface{ c() }
    55  type Z17 interface {
    56  	c() Y17
    57  	Y17 /* ERROR "duplicate method" */
    58  }
    59  func F17[T Z17](T) {}
    60  
    61  // crash 18
    62  type o18[T any] []func(_ o18[[]_ /* ERROR "cannot use _" */ ])
    63  
    64  // crash 19
    65  type Z19 [][[]Z19{}[0][0]]c19 /* ERROR "undefined" */
    66  
    67  // crash 20
    68  type Z20 /* ERROR "invalid recursive type" */ interface{ Z20 }
    69  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 ()" */ {}) }
    70  
    71  // crash 21
    72  type Z21 /* ERROR "invalid recursive type" */ interface{ Z21 }
    73  func F21[T Z21]() { ( /* ERROR "not used" */ F21[Z21]) }
    74  
    75  // crash 24
    76  type T24[P any] P // ERROR "cannot use a type parameter as RHS in type declaration"
    77  func (r T24[P]) m() { T24 /* ERROR "without instantiation" */ .m() }
    78  
    79  // crash 25
    80  type T25[A any] int
    81  func (t T25[A]) m1() {}
    82  var x T25 /* ERROR "without instantiation" */ .m1
    83  
    84  // crash 26
    85  type T26 = interface{ F26[ /* ERROR "interface method must have no type parameters" */ Z any]() }
    86  func F26[Z any]() T26 { return F26[] /* ERROR "operand" */ }
    87  
    88  // crash 27
    89  func e27[T any]() interface{ x27 /* ERROR "not a type" */ } { panic(0) }
    90  func x27() { e27 /* ERROR "cannot infer T" */ () }