Source file src/internal/types/testdata/fixedbugs/issue47747.go
1 // Copyright 2021 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 // For now, a lone type parameter is not permitted as RHS in a type declaration (issue #45639). 8 // type T1[P any] P 9 // 10 // func (T1[_]) m() {} 11 // 12 // func _[P any](x *T1[P]) { 13 // // x.m exists because x is of type *T1 where T1 is a defined type 14 // // (even though under(T1) is a type parameter) 15 // x.m() 16 // } 17 18 19 func _[P interface{ m() }](x P) { 20 x.m() 21 // (&x).m doesn't exist because &x is of type *P 22 // and pointers to type parameters don't have methods 23 (&x).m /* ERROR "type *P is pointer to type parameter, not type parameter" */ () 24 } 25 26 27 type T2 interface{ m() } 28 29 func _(x *T2) { 30 // x.m doesn't exists because x is of type *T2 31 // and pointers to interfaces don't have methods 32 x.m /* ERROR "type *T2 is pointer to interface, not interface" */() 33 } 34 35 // Test case 1 from issue 36 37 type Fooer1[t any] interface { 38 Foo(Barer[t]) 39 } 40 type Barer[t any] interface { 41 Bar(t) 42 } 43 44 // For now, a lone type parameter is not permitted as RHS in a type declaration (issue #45639). 45 // type Foo1[t any] t 46 // type Bar[t any] t 47 // 48 // func (l Foo1[t]) Foo(v Barer[t]) { v.Bar(t(l)) } 49 // func (b *Bar[t]) Bar(l t) { *b = Bar[t](l) } 50 // 51 // func _[t any](f Fooer1[t]) t { 52 // var b Bar[t] 53 // f.Foo(&b) 54 // return t(b) 55 // } 56 57 // Test case 2 from issue 58 59 // For now, a lone type parameter is not permitted as RHS in a type declaration (issue #45639). 60 // type Fooer2[t any] interface { 61 // Foo() 62 // } 63 // 64 // type Foo2[t any] t 65 // 66 // func (f *Foo2[t]) Foo() {} 67 // 68 // func _[t any](v t) { 69 // var f = Foo2[t](v) 70 // _ = Fooer2[t](&f) 71 // } 72