if (n.Op() == ir.ODOTINTER || n.Op() == ir.ODOTMETH) && !isCall {
n.SetOp(ir.OMETHVALUE)
- if len(n.X.Type().RParams()) > 0 || n.X.Type().IsPtr() && len(n.X.Type().Elem().RParams()) > 0 {
- // TODO: MethodValueWrapper needed for generics?
- // Or did we successfully desugar all that at stencil time?
- return n
- }
+ // This converts a method type to a function type. See issue 47775.
n.SetType(typecheck.NewMethodType(n.Type(), nil))
}
return n
// f is method type, with receiver.
// return function type, receiver as first argument (or not).
func NewMethodType(sig *types.Type, recv *types.Type) *types.Type {
+ if sig.HasTParam() {
+ base.Fatalf("NewMethodType with type parameters in signature %+v", sig)
+ }
+ if recv != nil && recv.HasTParam() {
+ base.Fatalf("NewMethodType with type parameters in receiver %+v", recv)
+ }
nrecvs := 0
if recv != nil {
nrecvs++
--- /dev/null
+// 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{}) {
+}
--- /dev/null
+// 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]()
+}
--- /dev/null
+// 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
--- /dev/null
+// 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]()
+}