diff options
Diffstat (limited to 'test')
-rw-r--r-- | test/typeparam/shape1.go | 33 | ||||
-rw-r--r-- | test/typeparam/shape1.out | 2 |
2 files changed, 35 insertions, 0 deletions
diff --git a/test/typeparam/shape1.go b/test/typeparam/shape1.go new file mode 100644 index 0000000000..3c9e71ea63 --- /dev/null +++ b/test/typeparam/shape1.go @@ -0,0 +1,33 @@ +// run -gcflags=-G=3 + +// Copyright 2021 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package main + +type I interface { + foo() int +} + +// There should be a single instantiation of f in this program. +func f[T I](x T) int { + return x.foo() +} + +type squarer int + +func (x squarer) foo() int { + return int(x*x) +} + +type doubler int + +func (x doubler) foo() int { + return int(2*x) +} + +func main() { + println(f(squarer(5))) + println(f(doubler(5))) +} diff --git a/test/typeparam/shape1.out b/test/typeparam/shape1.out new file mode 100644 index 0000000000..28391fde66 --- /dev/null +++ b/test/typeparam/shape1.out @@ -0,0 +1,2 @@ +25 +10 |