Source file src/internal/types/testdata/fixedbugs/issue70417.go
1 // Copyright 2024 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 // A0 10 type A0 = T[int] 11 type B0 = *T[int] 12 13 func (A0 /* ERROR "cannot define new methods on instantiated type T[int]" */) m() {} 14 func (*A0 /* ERROR "cannot define new methods on instantiated type T[int]" */) m() {} 15 func (B0 /* ERROR "cannot define new methods on instantiated type T[int]" */) m() {} 16 17 // A1 18 type A1[P any] = T[P] 19 type B1[P any] = *T[P] 20 21 func (A1 /* ERROR "cannot define new methods on generic alias type A1[P any]" */ [P]) m() {} 22 func (*A1 /* ERROR "cannot define new methods on generic alias type A1[P any]" */ [P]) m() {} 23 func (B1 /* ERROR "cannot define new methods on generic alias type B1[P any]" */ [P]) m() {} 24 25 // A2 26 type A2[P any] = T[int] 27 type B2[P any] = *T[int] 28 29 func (A2 /* ERROR "cannot define new methods on generic alias type A2[P any]" */ [P]) m() {} 30 func (*A2 /* ERROR "cannot define new methods on generic alias type A2[P any]" */ [P]) m() {} 31 func (B2 /* ERROR "cannot define new methods on generic alias type B2[P any]" */ [P]) m() {} 32 33 // A3 34 type A3 = T[int] 35 type B3 = *T[int] 36 37 func (A3 /* ERROR "cannot define new methods on instantiated type T[int]" */) m() {} 38 func (*A3 /* ERROR "cannot define new methods on instantiated type T[int]" */) m() {} 39 func (B3 /* ERROR "cannot define new methods on instantiated type T[int]" */) m() {} 40 41 // A4 42 type A4 = T // ERROR "cannot use generic type T[P any] without instantiation" 43 type B4 = *T // ERROR "cannot use generic type T[P any] without instantiation" 44 45 func (A4[P]) m1() {} // don't report a follow-on error on A4 46 func (*A4[P]) m2() {} // don't report a follow-on error on A4 47 func (B4[P]) m3() {} // don't report a follow-on error on B4 48 49 // instantiation in the middle of an alias chain 50 type S struct{} 51 type C0 = S 52 type C1[P any] = C0 53 type C2 = *C1[int] 54 55 func (C2 /* ERROR "cannot define new methods on instantiated type C1[int]" */) m() {} 56 func (*C2 /* ERROR "cannot define new methods on instantiated type C1[int]" */) m() {} 57