Skip to content

Commit 3b62e7e

Browse files
committed
go/ssa: use core type within (*builder).receiver
Change-Id: I677d99a2aeb6c7c8fa5362a371d781652d45aa35 Reviewed-on: https://go-review.googlesource.com/c/tools/+/498599 Reviewed-by: Alan Donovan <[email protected]> gopls-CI: kokoro <[email protected]> TryBot-Result: Gopher Robot <[email protected]> Run-TryBot: Tim King <[email protected]>
1 parent f394d45 commit 3b62e7e

File tree

2 files changed

+24
-5
lines changed

2 files changed

+24
-5
lines changed

go/ssa/builder.go

+4-5
Original file line numberDiff line numberDiff line change
@@ -829,7 +829,7 @@ func (b *builder) expr0(fn *Function, e ast.Expr, tv types.TypeAndValue) Value {
829829
// The result is a "bound".
830830
obj := sel.obj.(*types.Func)
831831
rt := fn.typ(recvType(obj))
832-
_, wantAddr := deptr(rt)
832+
_, wantAddr := deref(rt)
833833
escaping := true
834834
v := b.receiver(fn, e.X, wantAddr, escaping, sel)
835835

@@ -956,9 +956,8 @@ func (b *builder) stmtList(fn *Function, list []ast.Stmt) {
956956
//
957957
// escaping is defined as per builder.addr().
958958
func (b *builder) receiver(fn *Function, e ast.Expr, wantAddr, escaping bool, sel *selection) Value {
959-
960959
var v Value
961-
if _, eptr := deptr(fn.typeOf(e)); wantAddr && !sel.indirect && !eptr {
960+
if _, eptr := deref(fn.typeOf(e)); wantAddr && !sel.indirect && !eptr {
962961
v = b.addr(fn, e, escaping).address(fn)
963962
} else {
964963
v = b.expr(fn, e)
@@ -967,7 +966,7 @@ func (b *builder) receiver(fn *Function, e ast.Expr, wantAddr, escaping bool, se
967966
last := len(sel.index) - 1
968967
// The position of implicit selection is the position of the inducing receiver expression.
969968
v = emitImplicitSelections(fn, v, sel.index[:last], e.Pos())
970-
if _, vptr := deptr(v.Type()); !wantAddr && vptr {
969+
if _, vptr := deref(v.Type()); !wantAddr && vptr {
971970
v = emitLoad(fn, v)
972971
}
973972
return v
@@ -986,7 +985,7 @@ func (b *builder) setCallFunc(fn *Function, e *ast.CallExpr, c *CallCommon) {
986985
obj := sel.obj.(*types.Func)
987986
recv := recvType(obj)
988987

989-
_, wantAddr := deptr(recv)
988+
_, wantAddr := deref(recv)
990989
escaping := true
991990
v := b.receiver(fn, selector.X, wantAddr, escaping, sel)
992991
if types.IsInterface(recv) {

go/ssa/builder_generic_test.go

+20
Original file line numberDiff line numberDiff line change
@@ -690,6 +690,26 @@ func TestInstructionString(t *testing.T) {
690690
func f13[A [3]int, PA *A](v PA) {
691691
*v = A{7}
692692
}
693+
694+
//@ instrs("f14", "*ssa.Call", "invoke t1.Set(0:int)")
695+
func f14[T any, PT interface {
696+
Set(int)
697+
*T
698+
}]() {
699+
var t T
700+
p := PT(&t)
701+
p.Set(0)
702+
}
703+
704+
//@ instrs("f15", "*ssa.MakeClosure", "make closure (interface{Set(int); *T}).Set$bound [t1]")
705+
func f15[T any, PT interface {
706+
Set(int)
707+
*T
708+
}]() func(int) {
709+
var t T
710+
p := PT(&t)
711+
return p.Set
712+
}
693713
`
694714

695715
// Parse

0 commit comments

Comments
 (0)