]> Cypherpunks repositories - gostls13.git/commit
cmd/compile: fix unexpected type alias crash
authorMatthew Dempsky <mdempsky@google.com>
Wed, 28 Feb 2018 19:22:05 +0000 (11:22 -0800)
committerMatthew Dempsky <mdempsky@google.com>
Wed, 28 Feb 2018 20:18:37 +0000 (20:18 +0000)
commitb3f00c6985a28073c8ac20369597c2e982f4ef68
treef76b711ee2bda3c61959276fa69613ea0d98c4ef
parent1e308fbc1a5cc07c2a587bb56a175a0e2980f2e8
cmd/compile: fix unexpected type alias crash

OCOMPLIT stores the pre-typechecked type in n.Right, and then moves it
to n.Type. However, it wasn't clearing n.Right, so n.Right continued
to point to the OTYPE node. (Exception: slice literals reused n.Right
to store the array length.)

When exporting inline function bodies, we don't expect to need to save
any type aliases. Doing so wouldn't be wrong per se, but it's
completely unnecessary and would just bloat the export data.

However, reexportdep (whose role is to identify types needed by inline
function bodies) uses a generic tree traversal mechanism, which visits
n.Right even for O{ARRAY,MAP,STRUCT}LIT nodes. This means it finds the
OTYPE node, and mistakenly interpreted that the type alias needs to be
exported.

The straight forward fix is to just clear n.Right when typechecking
composite literals.

Fixes #24173.

Change-Id: Ia2d556bfdd806c83695b08e18b6cd71eff0772fc
Reviewed-on: https://go-review.googlesource.com/97719
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
Reviewed-by: Robert Griesemer <gri@golang.org>
src/cmd/compile/internal/gc/typecheck.go
test/fixedbugs/issue24173.go [new file with mode: 0644]