Source file test/typeparam/interfacearg.go
1 // run 2 3 // Copyright 2021 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 main 8 9 type I interface{} 10 11 type _S[T any] struct { 12 x *T 13 } 14 15 // F is a non-generic function, but has a type _S[I] which is instantiated from a 16 // generic type. Test that _S[I] is successfully exported. 17 func F() { 18 v := _S[I]{} 19 if v.x != nil { 20 panic(v) 21 } 22 } 23 24 // Testing the various combinations of method expressions. 25 type S1 struct{} 26 27 func (*S1) M() {} 28 29 type S2 struct{} 30 31 func (S2) M() {} 32 33 func _F1[T interface{ M() }](t T) { 34 _ = T.M 35 } 36 37 func F2() { 38 _F1(&S1{}) 39 _F1(S2{}) 40 _F1(&S2{}) 41 } 42 43 func main() { 44 F() 45 F2() 46 } 47