1
0
mirror of https://github.com/golang/go synced 2024-11-23 22:30:05 -07:00

cmd/compile: preserve Type.nod in copytype

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>
This commit is contained in:
Matthew Dempsky 2017-03-06 12:57:44 -08:00
parent 4b261a1410
commit 5d0c20efc7
2 changed files with 2 additions and 4 deletions

View File

@ -404,12 +404,10 @@ func (p *importer) newtyp(etype EType) *Type {
// importtype declares that pt, an imported named type, has underlying type t. // importtype declares that pt, an imported named type, has underlying type t.
func (p *importer) importtype(pt, t *Type) { func (p *importer) importtype(pt, t *Type) {
if pt.Etype == TFORW { if pt.Etype == TFORW {
n := pt.nod
copytype(pt.nod, t) copytype(pt.nod, t)
pt.nod = n // unzero nod
pt.Sym.Importdef = importpkg pt.Sym.Importdef = importpkg
pt.Sym.Lastlineno = lineno pt.Sym.Lastlineno = lineno
declare(n, PEXTERN) declare(pt.nod, PEXTERN)
checkwidth(pt) checkwidth(pt)
} else { } else {
// pt.Orig and t must be identical. // pt.Orig and t must be identical.

View File

@ -3566,7 +3566,7 @@ func copytype(n *Node, t *Type) {
} }
t.methods = Fields{} t.methods = Fields{}
t.allMethods = Fields{} t.allMethods = Fields{}
t.nod = nil t.nod = n
t.SetDeferwidth(false) t.SetDeferwidth(false)
t.ptrTo = ptrTo t.ptrTo = ptrTo
t.sliceOf = sliceOf t.sliceOf = sliceOf