aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorKeith Randall <khr@golang.org>2021-08-20 16:15:53 -0700
committerKeith Randall <khr@golang.org>2021-08-23 19:27:46 +0000
commit3081f817da8c194982596ddddf5d3ec321c859af (patch)
tree75122cd8b260c224a9d35a5d0e474a3e5a11a149 /test
parent8486ced8b09f4425bfd85e09b021dc78f93aea08 (diff)
downloadgo-3081f817da8c194982596ddddf5d3ec321c859af.tar.gz
go-3081f817da8c194982596ddddf5d3ec321c859af.zip
cmd/compile: always remove receiver type from instantiated method values
If a type T has a method foo, then var t T var i interface{} = t.foo The type of foo is a method type, but the type of t.foo should be a standard function type. Make sure we always do that conversion. Fixes #47775 Change-Id: I464ec792196b050aba1914e070a4ede34bfd0bfa Reviewed-on: https://go-review.googlesource.com/c/go/+/343881 Trust: Keith Randall <khr@golang.org> Trust: Dan Scales <danscales@google.com> Reviewed-by: Matthew Dempsky <mdempsky@google.com> Reviewed-by: Dan Scales <danscales@google.com>
Diffstat (limited to 'test')
-rw-r--r--test/typeparam/issue47775.dir/b.go19
-rw-r--r--test/typeparam/issue47775.dir/main.go11
-rw-r--r--test/typeparam/issue47775.go7
-rw-r--r--test/typeparam/issue47775b.go28
4 files changed, 65 insertions, 0 deletions
diff --git a/test/typeparam/issue47775.dir/b.go b/test/typeparam/issue47775.dir/b.go
new file mode 100644
index 0000000000..b6d7ba97c5
--- /dev/null
+++ b/test/typeparam/issue47775.dir/b.go
@@ -0,0 +1,19 @@
+// 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 b
+
+type C[T any] struct {
+}
+
+func (c *C[T]) reset() {
+}
+
+func New[T any]() {
+ c := &C[T]{}
+ z(c.reset)
+}
+
+func z(interface{}) {
+}
diff --git a/test/typeparam/issue47775.dir/main.go b/test/typeparam/issue47775.dir/main.go
new file mode 100644
index 0000000000..ed284ddfc6
--- /dev/null
+++ b/test/typeparam/issue47775.dir/main.go
@@ -0,0 +1,11 @@
+// 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
+
+import "b"
+
+func main() {
+ b.New[int]()
+}
diff --git a/test/typeparam/issue47775.go b/test/typeparam/issue47775.go
new file mode 100644
index 0000000000..76930e5e4f
--- /dev/null
+++ b/test/typeparam/issue47775.go
@@ -0,0 +1,7 @@
+// rundir -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 ignored
diff --git a/test/typeparam/issue47775b.go b/test/typeparam/issue47775b.go
new file mode 100644
index 0000000000..6d3fc8df97
--- /dev/null
+++ b/test/typeparam/issue47775b.go
@@ -0,0 +1,28 @@
+// 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 C[T any] struct {
+}
+
+func (c *C[T]) reset() {
+}
+
+func New[T any]() {
+ c := &C[T]{}
+ i = c.reset
+ z(c.reset)
+}
+
+var i interface{}
+
+func z(interface{}) {
+}
+
+func main() {
+ New[int]()
+}