]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile: generate interface method expression wrapper for error.Error
authorRobert Griesemer <gri@golang.org>
Mon, 17 Dec 2018 19:33:42 +0000 (11:33 -0800)
committerRobert Griesemer <gri@golang.org>
Mon, 17 Dec 2018 19:48:36 +0000 (19:48 +0000)
A prior optimization (https://golang.org/cl/106175) removed the
generation of unnecessary method expression wrappers, but also
eliminated the generation of the wrapper for error.Error which
was still required.

Special-case error type in the optimization.

Fixes #29304.

Change-Id: I54c8afc88a2c6d1906afa2d09c68a0a3f3e2f1e3
Reviewed-on: https://go-review.googlesource.com/c/154578
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
src/cmd/compile/internal/gc/subr.go
test/fixedbugs/issue29304.go [new file with mode: 0644]

index 629186829a5af4981e5c07efcbd8797eca61402b..2a976dc4f03a91a26e190f07e1aed4db0df93144 100644 (file)
@@ -1517,8 +1517,9 @@ func genwrapper(rcvr *types.Type, method *types.Field, newnam *types.Sym) {
                return
        }
 
-       // Only generate I.M wrappers for I in I's own package.
-       if rcvr.IsInterface() && rcvr.Sym != nil && rcvr.Sym.Pkg != localpkg {
+       // Only generate I.M wrappers for I in I's own package
+       // but keep doing it for error.Error (was issue #29304).
+       if rcvr.IsInterface() && rcvr.Sym != nil && rcvr.Sym.Pkg != localpkg && rcvr != types.Errortype {
                return
        }
 
diff --git a/test/fixedbugs/issue29304.go b/test/fixedbugs/issue29304.go
new file mode 100644 (file)
index 0000000..47bc99f
--- /dev/null
@@ -0,0 +1,19 @@
+// run
+
+// 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.
+
+// Verify that relocation target go.builtin.error.Error
+// is defined and the code links and runs correctly.
+
+package main
+
+import "errors"
+
+func main() {
+       err := errors.New("foo")
+       if error.Error(err) != "foo" {
+               panic("FAILED")
+       }
+}