]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile: simplify exporting universal 'error' type
authorMatthew Dempsky <mdempsky@google.com>
Wed, 6 Sep 2017 01:49:36 +0000 (18:49 -0700)
committerMatthew Dempsky <mdempsky@google.com>
Wed, 6 Sep 2017 20:14:17 +0000 (20:14 +0000)
There shouldn't be any problems setting error's "Orig" (underlying)
type to a separate anonymous interface, as this is already how
go/types defines it.

Change-Id: I44e9c4048ffe362ce329e8306632e38b5ccfecff
Reviewed-on: https://go-review.googlesource.com/61790
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Daniel Martí <mvdan@mvdan.cc>
Reviewed-by: Alan Donovan <adonovan@google.com>
src/cmd/compile/internal/gc/bexport.go
src/cmd/compile/internal/gc/universe.go

index 3ac81367048c8ea5c96095d6f5da61bde898a1da..076b8a91e2442cf4696e99667da12cd75bd03b20 100644 (file)
@@ -601,8 +601,6 @@ func isInlineable(n *Node) bool {
        return false
 }
 
-var errorInterface *types.Type // lazily initialized
-
 func (p *exporter) typ(t *types.Type) {
        if t == nil {
                Fatalf("exporter: nil type")
@@ -654,19 +652,7 @@ func (p *exporter) typ(t *types.Type) {
                p.qualifiedName(tsym)
 
                // write underlying type
-               orig := t.Orig
-               if orig == types.Errortype {
-                       // The error type is the only predeclared type which has
-                       // a composite underlying type. When we encode that type,
-                       // make sure to encode the underlying interface rather than
-                       // the named type again. See also the comment in universe.go
-                       // regarding the errortype and issue #15920.
-                       if errorInterface == nil {
-                               errorInterface = makeErrorInterface()
-                       }
-                       orig = errorInterface
-               }
-               p.typ(orig)
+               p.typ(t.Orig)
 
                // interfaces don't have associated methods
                if t.Orig.IsInterface() {
index 31a15d272da6a905dadf9df712c984aae588fa44..ea901db744fcd3a19990e2df1e954bfd098bc478 100644 (file)
@@ -385,10 +385,7 @@ func lexinit1() {
        s := builtinpkg.Lookup("error")
        types.Errortype = makeErrorInterface()
        types.Errortype.Sym = s
-       // TODO: If we can prove that it's safe to set errortype.Orig here
-       // than we don't need the special errortype/errorInterface case in
-       // bexport.go. See also issue #15920.
-       // errortype.Orig = makeErrorInterface()
+       types.Errortype.Orig = makeErrorInterface()
        s.Def = asTypesNode(typenod(types.Errortype))
 
        // We create separate byte and rune types for better error messages