compiler/cl/_testgo: add tpinst

This commit is contained in:
visualfc
2025-02-01 10:55:06 +08:00
parent 7bc7f23125
commit 4f5468469b
6 changed files with 532 additions and 19 deletions

View File

@@ -0,0 +1,37 @@
package main
type M[T interface{}] struct {
v T
}
func (pt *M[T]) Value() T {
return pt.v
}
func (pt *M[T]) value() T {
return pt.v
}
type I[T interface{}] interface {
Value() T
}
func demo() {
var v1 I[int] = &M[int]{100}
if v1.Value() != 100 {
panic("error")
}
var v2 I[float64] = &M[float64]{100.1}
if v2.Value() != 100.1 {
panic("error")
}
if v1.(interface{ value() int }).value() != 100 {
panic("error")
}
}
func main() {
demo()
}