src/cmd/compile/internal/noder/reader.go | 13 ++++++++++++- test/fixedbugs/issue58563.dir/a.go | 13 +++++++++++++ test/fixedbugs/issue58563.dir/main.go | 16 ++++++++++++++++ test/fixedbugs/issue58563.go | 7 +++++++ diff --git a/src/cmd/compile/internal/noder/reader.go b/src/cmd/compile/internal/noder/reader.go index 591d09ba783efb905342981e2b2341545889d8fa..bc2151e178c580264989b391d07aa281251dbfd4 100644 --- a/src/cmd/compile/internal/noder/reader.go +++ b/src/cmd/compile/internal/noder/reader.go @@ -2194,7 +2194,18 @@ recv = typecheck.Expr(ir.NewConvExpr(recv.Pos(), ir.OCONVNOP, typ, recv)) } n := typecheck.Expr(ir.NewSelectorExpr(pos, ir.OXDOT, recv, wrapperFn.Sel)).(*ir.SelectorExpr) - assert(n.Selection == wrapperFn.Selection) + + // As a consistency check here, we make sure "n" selected the + // same method (represented by a types.Field) that wrapperFn + // selected. However, for anonymous receiver types, there can be + // multiple such types.Field instances (#58563). So we may need + // to fallback to making sure Sym and Type (including the + // receiver parameter's type) match. + if n.Selection != wrapperFn.Selection { + assert(n.Selection.Sym == wrapperFn.Selection.Sym) + assert(types.Identical(n.Selection.Type, wrapperFn.Selection.Type)) + assert(types.Identical(n.Selection.Type.Recv().Type, wrapperFn.Selection.Type.Recv().Type)) + } wrapper := methodValueWrapper{ rcvr: n.X.Type(), diff --git a/test/fixedbugs/issue58563.dir/a.go b/test/fixedbugs/issue58563.dir/a.go new file mode 100644 index 0000000000000000000000000000000000000000..2b716c1b334a0586ca4a0ce28bd1c42ad5242137 --- /dev/null +++ b/test/fixedbugs/issue58563.dir/a.go @@ -0,0 +1,13 @@ +// Copyright 2023 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 a + +func Start() interface{ Stop() } { + return new(Stopper) +} + +type Stopper struct{} + +func (s *Stopper) Stop() {} diff --git a/test/fixedbugs/issue58563.dir/main.go b/test/fixedbugs/issue58563.dir/main.go new file mode 100644 index 0000000000000000000000000000000000000000..18a90fcf056c0f515fc477aefdcefbb9a755ff96 --- /dev/null +++ b/test/fixedbugs/issue58563.dir/main.go @@ -0,0 +1,16 @@ +// Copyright 2023 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 "test/a" + +func main() { + stop := start() + defer stop() +} + +func start() func() { + return a.Start().Stop +} diff --git a/test/fixedbugs/issue58563.go b/test/fixedbugs/issue58563.go new file mode 100644 index 0000000000000000000000000000000000000000..5c4c5c0a8fb9072a250cb3bfa8a9718e7d06f921 --- /dev/null +++ b/test/fixedbugs/issue58563.go @@ -0,0 +1,7 @@ +// compiledir + +// Copyright 2023 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