aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorKeith Randall <khr@golang.org>2021-07-30 14:00:27 -0700
committerKeith Randall <khr@golang.org>2021-07-31 17:03:07 +0000
commit0b8a9ccb25cd9b8f78eb47b1934522af3fb4108f (patch)
treecb79c4ab8790ab8f71fe262dd76eb81e602ce210 /test
parent7bed50e667cf1b4ba5b2ec7ca699c835c696e454 (diff)
downloadgo-0b8a9ccb25cd9b8f78eb47b1934522af3fb4108f.tar.gz
go-0b8a9ccb25cd9b8f78eb47b1934522af3fb4108f.zip
[dev.typeparams] cmd/compile: make all pointer types have the same shape
Except unsafe.Pointer. It has a different Kind, which makes it trickier. Change-Id: I12582afb6e591bea35da9e43ac8d141ed19532a3 Reviewed-on: https://go-review.googlesource.com/c/go/+/338749 Trust: Keith Randall <khr@golang.org> Trust: Dan Scales <danscales@google.com> Run-TryBot: Keith Randall <khr@golang.org> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Dan Scales <danscales@google.com>
Diffstat (limited to 'test')
-rw-r--r--test/typeparam/shape1.go19
-rw-r--r--test/typeparam/shape1.out2
2 files changed, 20 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))
}
diff --git a/test/typeparam/shape1.out b/test/typeparam/shape1.out
index 28391fde66..da9a12ded5 100644
--- a/test/typeparam/shape1.out
+++ b/test/typeparam/shape1.out
@@ -1,2 +1,4 @@
25
10
+6
+4