]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile: preserve Type.nod in copytype
authorMatthew Dempsky <mdempsky@google.com>
Mon, 6 Mar 2017 20:57:44 +0000 (12:57 -0800)
committerMatthew Dempsky <mdempsky@google.com>
Mon, 6 Mar 2017 22:16:05 +0000 (22:16 +0000)
By clearing out t.nod in copytype, we effectively lose the reference
from a Type back to its declaring OTYPE Node. This means later in
typenamesym when we add typenod(t) to signatlist, we end up creating a
new OTYPE Node. Moreover, this Node's position information will depend
on whatever context it happens be needed, and will be used for the
Type's position in the export data.

Updates #19391.

Change-Id: Ied93126449f75d7c5e3275cbdcc6fa657a8aa21d
Reviewed-on: https://go-review.googlesource.com/37870
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
Run-TryBot: Robert Griesemer <gri@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Robert Griesemer <gri@golang.org>
src/cmd/compile/internal/gc/bimport.go
src/cmd/compile/internal/gc/typecheck.go

index 34cb70d9c874e24b208edaf839d2aa618a28fa5e..d6a25515dff30dc4e261e66ccfcc7cafba3ea522 100644 (file)
@@ -404,12 +404,10 @@ func (p *importer) newtyp(etype EType) *Type {
 // importtype declares that pt, an imported named type, has underlying type t.
 func (p *importer) importtype(pt, t *Type) {
        if pt.Etype == TFORW {
-               n := pt.nod
                copytype(pt.nod, t)
-               pt.nod = n // unzero nod
                pt.Sym.Importdef = importpkg
                pt.Sym.Lastlineno = lineno
-               declare(n, PEXTERN)
+               declare(pt.nod, PEXTERN)
                checkwidth(pt)
        } else {
                // pt.Orig and t must be identical.
index 4923c3ec8a3dc8e9d2a77d5781612af3ac326c5d..180bd70cc1ab69dd00de119a17f187772d460bd9 100644 (file)
@@ -3566,7 +3566,7 @@ func copytype(n *Node, t *Type) {
        }
        t.methods = Fields{}
        t.allMethods = Fields{}
-       t.nod = nil
+       t.nod = n
        t.SetDeferwidth(false)
        t.ptrTo = ptrTo
        t.sliceOf = sliceOf