aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobert Griesemer <gri@golang.org>2018-12-17 11:33:42 -0800
committerBrad Fitzpatrick <bradfitz@golang.org>2018-12-17 22:39:23 +0000
commita171e155000d1f40a6e467e56b4af3a237613c1f (patch)
tree11b9e9ed6c0d3d350de2673f0edef013da0b4b3d
parent4601a4c1b1c00fbe507508f0267ec5a9445bb7e5 (diff)
downloadgo-a171e155000d1f40a6e467e56b4af3a237613c1f.tar.gz
go-a171e155000d1f40a6e467e56b4af3a237613c1f.zip
[release-branch.go1.11] cmd/compile: generate interface method expression wrapper for error.Error
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 #29307 Change-Id: I54c8afc88a2c6d1906afa2d09c68a0a3f3e2f1e3 Reviewed-on: https://go-review.googlesource.com/c/154578 Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org> (cherry picked from commit a1aafd8b28ada0d40e2cb25fb0762ae171eec558) Reviewed-on: https://go-review.googlesource.com/c/154579 Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org>
-rw-r--r--src/cmd/compile/internal/gc/subr.go5
-rw-r--r--test/fixedbugs/issue29304.go19
2 files changed, 22 insertions, 2 deletions
diff --git a/src/cmd/compile/internal/gc/subr.go b/src/cmd/compile/internal/gc/subr.go
index c926b147de..622699e4ae 100644
--- a/src/cmd/compile/internal/gc/subr.go
+++ b/src/cmd/compile/internal/gc/subr.go
@@ -1627,8 +1627,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
index 0000000000..47bc99f9ca
--- /dev/null
+++ b/test/fixedbugs/issue29304.go
@@ -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")
+ }
+}