Skip to content

Commit fe73f28

Browse files
committed
[dev.typeparams] cmd/compile: set sym.Def to ir.Name for method value wrappers
The code for generating method value wrappers is weird that it sets sym.Def to the generated ir.Func, whereas normally sym.Def points to ir.Name. While here, change methodValueWrapper to return the ir.Name too, since that's what the caller wants. Change-Id: I3da5320ca0bf4d32d7b420345454f19075d19a26 Reviewed-on: https://go-review.googlesource.com/c/go/+/339410 Trust: Matthew Dempsky <mdempsky@google.com> Trust: Cuong Manh Le <cuong.manhle.vn@gmail.com> Run-TryBot: Matthew Dempsky <mdempsky@google.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Cuong Manh Le <cuong.manhle.vn@gmail.com>
1 parent 656f088 commit fe73f28

File tree

2 files changed

+7
-7
lines changed

2 files changed

+7
-7
lines changed

src/cmd/compile/internal/noder/reader.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2253,7 +2253,7 @@ func (r *reader) methodValueWrapper(tbase *types.Type, method *types.Field, targ
22532253
pos := base.AutogeneratedPos
22542254

22552255
fn := r.newWrapperFunc(pos, sym, nil, method)
2256-
sym.Def = fn
2256+
sym.Def = fn.Nname
22572257

22582258
// Declare and initialize variable holding receiver.
22592259
recv := ir.NewHiddenParam(pos, fn, typecheck.Lookup(".this"), recvType)

src/cmd/compile/internal/walk/closure.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ func walkMethodValue(n *ir.SelectorExpr, init *ir.Nodes) ir.Node {
179179

180180
clos := ir.NewCompLitExpr(base.Pos, ir.OCOMPLIT, ir.TypeNode(typ), nil)
181181
clos.SetEsc(n.Esc())
182-
clos.List = []ir.Node{ir.NewUnaryExpr(base.Pos, ir.OCFUNC, methodValueWrapper(n).Nname), n.X}
182+
clos.List = []ir.Node{ir.NewUnaryExpr(base.Pos, ir.OCFUNC, methodValueWrapper(n)), n.X}
183183

184184
addr := typecheck.NodAddr(clos)
185185
addr.SetEsc(n.Esc())
@@ -199,11 +199,11 @@ func walkMethodValue(n *ir.SelectorExpr, init *ir.Nodes) ir.Node {
199199
return walkExpr(cfn, init)
200200
}
201201

202-
// methodValueWrapper returns the DCLFUNC node representing the
202+
// methodValueWrapper returns the ONAME node representing the
203203
// wrapper function (*-fm) needed for the given method value. If the
204204
// wrapper function hasn't already been created yet, it's created and
205205
// added to typecheck.Target.Decls.
206-
func methodValueWrapper(dot *ir.SelectorExpr) *ir.Func {
206+
func methodValueWrapper(dot *ir.SelectorExpr) *ir.Name {
207207
if dot.Op() != ir.OMETHVALUE {
208208
base.Fatalf("methodValueWrapper: unexpected %v (%v)", dot, dot.Op())
209209
}
@@ -214,7 +214,7 @@ func methodValueWrapper(dot *ir.SelectorExpr) *ir.Func {
214214
sym := ir.MethodSymSuffix(rcvrtype, meth, "-fm")
215215

216216
if sym.Uniq() {
217-
return sym.Def.(*ir.Func)
217+
return sym.Def.(*ir.Name)
218218
}
219219
sym.SetUniq(true)
220220

@@ -262,10 +262,10 @@ func methodValueWrapper(dot *ir.SelectorExpr) *ir.Func {
262262
// typecheckslice() requires that Curfn is set when processing an ORETURN.
263263
ir.CurFunc = fn
264264
typecheck.Stmts(fn.Body)
265-
sym.Def = fn
265+
sym.Def = fn.Nname
266266
typecheck.Target.Decls = append(typecheck.Target.Decls, fn)
267267
ir.CurFunc = savecurfn
268268
base.Pos = saveLineNo
269269

270-
return fn
270+
return fn.Nname
271271
}

0 commit comments

Comments
 (0)