]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile: set correct line number for method wrappers
authorKeith Randall <khr@google.com>
Mon, 10 Dec 2018 22:19:33 +0000 (14:19 -0800)
committerKeith Randall <khr@golang.org>
Mon, 10 Dec 2018 23:31:21 +0000 (23:31 +0000)
When converting a method to a function, like this:

type T ...
func (t T) foo() {
}
var t T
f := t.foo

We need to build a wrapper function for the partially evaluated
method. Currently that wrapper function gets the line number of
the first place where t.foo appears. Instead it should have the
line number of where foo is declared.

Fixes #26839

Change-Id: I7dbe2094e53d5d336f329273f10f8430e0af544e
Reviewed-on: https://go-review.googlesource.com/c/153498
Run-TryBot: Keith Randall <khr@golang.org>
Reviewed-by: Robert Griesemer <gri@golang.org>
src/cmd/compile/internal/gc/closure.go

index 07064415f499ead9b79b00b95e88430137dc9428..f6b492a16f029d2377cf6ffeb1cdaf8f846aadbd 100644 (file)
@@ -434,8 +434,15 @@ func makepartialcall(fn *Node, t0 *types.Type, meth *types.Sym) *Node {
        sym.SetUniq(true)
 
        savecurfn := Curfn
+       saveLineNo := lineno
        Curfn = nil
 
+       // Set line number equal to the line number where the method is declared.
+       var m *types.Field
+       if lookdot0(meth, rcvrtype, &m, false) == 1 {
+               lineno = m.Pos
+       }
+
        tfn := nod(OTFUNC, nil, nil)
        tfn.List.Set(structargs(t0.Params(), true))
        tfn.Rlist.Set(structargs(t0.Results(), false))
@@ -482,6 +489,7 @@ func makepartialcall(fn *Node, t0 *types.Type, meth *types.Sym) *Node {
        sym.Def = asTypesNode(xfunc)
        xtop = append(xtop, xfunc)
        Curfn = savecurfn
+       lineno = saveLineNo
 
        return xfunc
 }