diff options
-rw-r--r-- | src/cmd/compile/internal/inline/inl.go | 4 | ||||
-rw-r--r-- | test/typeparam/issue54911.go | 21 |
2 files changed, 23 insertions, 2 deletions
diff --git a/src/cmd/compile/internal/inline/inl.go b/src/cmd/compile/internal/inline/inl.go index 716a7fbcd9..bc7ec5cf20 100644 --- a/src/cmd/compile/internal/inline/inl.go +++ b/src/cmd/compile/internal/inline/inl.go @@ -771,18 +771,18 @@ func mkinlcall(n *ir.CallExpr, fn *ir.Func, maxCost int32, inlMap map[*ir.Func]b // CalleeEffects appends any side effects from evaluating callee to init. func CalleeEffects(init *ir.Nodes, callee ir.Node) { for { + init.Append(ir.TakeInit(callee)...) + switch callee.Op() { case ir.ONAME, ir.OCLOSURE, ir.OMETHEXPR: return // done case ir.OCONVNOP: conv := callee.(*ir.ConvExpr) - init.Append(ir.TakeInit(conv)...) callee = conv.X case ir.OINLCALL: ic := callee.(*ir.InlinedCallExpr) - init.Append(ir.TakeInit(ic)...) init.Append(ic.Body.Take()...) callee = ic.SingleResult() diff --git a/test/typeparam/issue54911.go b/test/typeparam/issue54911.go new file mode 100644 index 0000000000..0df2b99563 --- /dev/null +++ b/test/typeparam/issue54911.go @@ -0,0 +1,21 @@ +// compile -G=3 + +// Copyright 2022 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 Set[T comparable] map[T]struct{} + +func (s Set[T]) Add() Set[T] { + return s +} + +func (s Set[T]) Copy() Set[T] { + return Set[T].Add(s) +} + +func main() { + _ = Set[int]{42: {}} +} |