Text file src/go/types/testdata/fixedbugs/issue39634.go2

     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 undeclared name */ }
    13  type ph1[e nt1[e],g(d /* ERROR undeclared name */ )]s /* ERROR undeclared name */
    14  func(*ph1[e,e /* ERROR redeclared */ ])h(d /* ERROR undeclared name */ )
    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 no field or method p */ }
    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  // Embedding stand-alone type parameters is not permitted for now. Disabled.
    35  // type foo8[A any] interface { ~A }
    36  // func bar8[A foo8[A]](a A) {}
    37  // func main8() {}
    38  
    39  // crash 9
    40  type foo9[A any] interface { foo9 /* ERROR illegal cycle */ [A] }
    41  func _() { var _ = new(foo9[int]) }
    42  
    43  // crash 12
    44  var u /* ERROR cycle */ , i [func /* ERROR used as value */ /* ERROR used as value */ (u, c /* ERROR undeclared */ /* ERROR undeclared */ ) {}(0, len /* ERROR must be called */ /* ERROR must be called */ )]c /* ERROR undeclared */ /* ERROR undeclared */
    45  
    46  // crash 15
    47  func y15() { var a /* ERROR declared but not used */ interface{ p() } = G15[string]{} }
    48  type G15[X any] s /* ERROR undeclared name */
    49  func (G15 /* ERROR generic type .* without instantiation */ ) p()
    50  
    51  // crash 16
    52  type Foo16[T any] r16 /* ERROR not a type */
    53  func r16[T any]() Foo16[Foo16[T]] { panic(0) }
    54  
    55  // crash 17
    56  type Y17 interface{ c() }
    57  type Z17 interface {
    58  	c() Y17
    59  	Y17 /* ERROR duplicate method */
    60  }
    61  func F17[T Z17](T) {}
    62  
    63  // crash 18
    64  type o18[T any] []func(_ o18[[]_ /* ERROR cannot use _ */ ])
    65  
    66  // crash 19
    67  type Z19 [][[]Z19{}[0][0]]c19 /* ERROR undeclared */
    68  
    69  // crash 20
    70  type Z20 /* ERROR illegal cycle */ interface{ Z20 }
    71  func F20[t Z20]() { F20(t /* ERROR invalid composite literal type */ {}) }
    72  
    73  // crash 21
    74  type Z21 /* ERROR illegal cycle */ interface{ Z21 }
    75  func F21[T Z21]() { ( /* ERROR not used */ F21[Z21]) }
    76  
    77  // For now, a lone type parameter is not permitted as RHS in a type declaration (issue #45639).
    78  // // crash 24
    79  // type T24[P any] P
    80  // func (r T24[P]) m() { T24 /* ERROR without instantiation */ .m() }
    81  
    82  // crash 25
    83  type T25[A any] int
    84  func (t T25[A]) m1() {}
    85  var x T25 /* ERROR without instantiation */ .m1
    86  
    87  // crash 26
    88  type T26 = interface{ F26[ /* ERROR interface method must have no type parameters */ Z any]() }
    89  // The error messages on the line below differ from types2 because for backward
    90  // compatibility go/parser must produce an IndexExpr with BadExpr index for the
    91  // expression F26[].
    92  func F26[Z any]() T26 { return F26[] /* ERROR operand */ }
    93  
    94  // crash 27
    95  func e27[T any]() interface{ x27 /* ERROR not a type */ } { panic(0) }
    96  func x27() { e27 /* ERROR cannot infer T */ () }
    97  

View as plain text