diff options
Diffstat (limited to 'test/typeparam/shape1.go')
-rw-r--r-- | test/typeparam/shape1.go | 19 |
1 files changed, 18 insertions, 1 deletions
diff --git a/test/typeparam/shape1.go b/test/typeparam/shape1.go index 3c9e71ea63..de1ea65ed2 100644 --- a/test/typeparam/shape1.go +++ b/test/typeparam/shape1.go @@ -10,7 +10,8 @@ type I interface { foo() int } -// There should be a single instantiation of f in this program. +// There should be one instantiation of f for both squarer and doubler. +// Similarly, there should be one instantiation of f for both *incrementer and *decrementer. func f[T I](x T) int { return x.foo() } @@ -27,7 +28,23 @@ func (x doubler) foo() int { return int(2*x) } +type incrementer int16 + +func (x *incrementer) foo() int { + return int(*x+1) +} + +type decrementer int32 + +func (x *decrementer) foo() int{ + return int(*x-1) +} + func main() { println(f(squarer(5))) println(f(doubler(5))) + var i incrementer = 5 + println(f(&i)) + var d decrementer = 5 + println(f(&d)) } |