]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile: fix line number for implicitly declared method expressions
authorKeith Randall <khr@google.com>
Fri, 21 Dec 2018 23:41:28 +0000 (15:41 -0800)
committerKeith Randall <khr@golang.org>
Sat, 22 Dec 2018 01:08:39 +0000 (01:08 +0000)
Method expressions where the method is implicitly declared have no
line number. The Error method of the built-in error type is one such
method.  We leave the line number at the use of the method expression
in this case.

Fixes #29389

Change-Id: I29c64bb47b1a704576abf086599eb5af7b78df53
Reviewed-on: https://go-review.googlesource.com/c/155639
Run-TryBot: Keith Randall <khr@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
src/cmd/compile/internal/gc/closure.go
test/fixedbugs/issue29389.go [new file with mode: 0644]

index f6b492a16f029d2377cf6ffeb1cdaf8f846aadbd..284ecdf457ce34499b3439dcb4889f34248ecf8f 100644 (file)
@@ -439,9 +439,14 @@ func makepartialcall(fn *Node, t0 *types.Type, meth *types.Sym) *Node {
 
        // Set line number equal to the line number where the method is declared.
        var m *types.Field
-       if lookdot0(meth, rcvrtype, &m, false) == 1 {
+       if lookdot0(meth, rcvrtype, &m, false) == 1 && m.Pos.IsKnown() {
                lineno = m.Pos
        }
+       // Note: !m.Pos.IsKnown() happens for method expressions where
+       // the method is implicitly declared. The Error method of the
+       // built-in error type is one such method.  We leave the line
+       // number at the use of the method expression in this
+       // case. See issue 29389.
 
        tfn := nod(OTFUNC, nil, nil)
        tfn.List.Set(structargs(t0.Params(), true))
diff --git a/test/fixedbugs/issue29389.go b/test/fixedbugs/issue29389.go
new file mode 100644 (file)
index 0000000..43859fd
--- /dev/null
@@ -0,0 +1,17 @@
+// compile
+
+// Copyright 2018 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.
+
+// Make sure we can correctly compile method expressions
+// where the method is implicitly declared.
+
+package main
+
+import "io"
+
+func main() {
+       err := io.EOF
+       _ = err.Error
+}