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

     1  // -gotypesalias=1
     2  
     3  // Copyright 2024 The Go Authors. All rights reserved.
     4  // Use of this source code is governed by a BSD-style
     5  // license that can be found in the LICENSE file.
     6  
     7  package p
     8  
     9  type T[P any] struct{}
    10  
    11  // A0
    12  type A0 = T[int]
    13  type B0 = *T[int]
    14  
    15  func (A0 /* ERROR "cannot define new methods on instantiated type T[int]" */) m()  {}
    16  func (*A0 /* ERROR "cannot define new methods on instantiated type T[int]" */) m() {}
    17  func (B0 /* ERROR "cannot define new methods on instantiated type T[int]" */) m()  {}
    18  
    19  // A1
    20  type A1[P any] = T[P]
    21  type B1[P any] = *T[P]
    22  
    23  func (A1 /* ERROR "cannot define new methods on generic alias type A1[P any]" */ [P]) m()  {}
    24  func (*A1 /* ERROR "cannot define new methods on generic alias type A1[P any]" */ [P]) m() {}
    25  func (B1 /* ERROR "cannot define new methods on generic alias type B1[P any]" */ [P]) m()  {}
    26  
    27  // A2
    28  type A2[P any] = T[int]
    29  type B2[P any] = *T[int]
    30  
    31  func (A2 /* ERROR "cannot define new methods on generic alias type A2[P any]" */ [P]) m()  {}
    32  func (*A2 /* ERROR "cannot define new methods on generic alias type A2[P any]" */ [P]) m() {}
    33  func (B2 /* ERROR "cannot define new methods on generic alias type B2[P any]" */ [P]) m()  {}
    34  
    35  // A3
    36  type A3 = T[int]
    37  type B3 = *T[int]
    38  
    39  func (A3 /* ERROR "cannot define new methods on instantiated type T[int]" */) m()  {}
    40  func (*A3 /* ERROR "cannot define new methods on instantiated type T[int]" */) m() {}
    41  func (B3 /* ERROR "cannot define new methods on instantiated type T[int]" */) m()  {}
    42  
    43  // A4
    44  type A4 = T  // ERROR "cannot use generic type T[P any] without instantiation"
    45  type B4 = *T // ERROR "cannot use generic type T[P any] without instantiation"
    46  
    47  func (A4[P]) m1()  {} // don't report a follow-on error on A4
    48  func (*A4[P]) m2() {} // don't report a follow-on error on A4
    49  func (B4[P]) m3()  {} // don't report a follow-on error on B4
    50  
    51  // instantiation in the middle of an alias chain
    52  type S struct{}
    53  type C0 = S
    54  type C1[P any] = C0
    55  type C2 = *C1[int]
    56  
    57  func (C2 /* ERROR "cannot define new methods on instantiated type C1[int]" */) m()  {}
    58  func (*C2 /* ERROR "cannot define new methods on instantiated type C1[int]" */) m() {}
    59  

View as plain text