]> Cypherpunks repositories - gostls13.git/commit
cmd/compile: allow composite literal structs with _ fields
authorJosh Bleecher Snyder <josharian@gmail.com>
Fri, 10 Mar 2017 06:41:32 +0000 (22:41 -0800)
committerJosh Bleecher Snyder <josharian@gmail.com>
Fri, 7 Apr 2017 22:01:18 +0000 (22:01 +0000)
commitc9446398e8d72263f75c11bb835d75421627b3a3
tree25b63ae7164fbbbd6212533d289fe9389dbb28e8
parent44a0681ae4e5d92fe86087a3d70aab2ad8df0f10
cmd/compile: allow composite literal structs with _ fields

Given code such as

type T struct {
  _ string
}

func f() {
  var x = T{"space"}
  // ...
}

the compiler rewrote the 'var x' line as

var x T
x._ = "space"

The compiler then rejected the assignment to
a blank field, thus rejecting valid code.

It also failed to catch a number of invalid assignments.
And there were insufficient checks for validity
when emitting static data, leading to ICEs.

To fix, check earlier for explicit blanks field names,
explicitly handle legit blanks in sinit,
and don't try to emit static data for nodes
for which typechecking has failed.

Fixes #19482

Change-Id: I594476171d15e6e8ecc6a1749e3859157fe2c929
Reviewed-on: https://go-review.googlesource.com/38006
Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
src/cmd/compile/internal/gc/sinit.go
src/cmd/compile/internal/gc/typecheck.go
src/cmd/internal/obj/data.go
test/fixedbugs/issue19482.go [new file with mode: 0644]