• Josh Bleecher Snyder's avatar
    cmd/compile: allow composite literal structs with _ fields · c9446398
    Josh Bleecher Snyder authored
    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: 's avatarMatthew Dempsky <mdempsky@google.com>
    TryBot-Result: Gobot Gobot <gobot@golang.org>
    c9446398
sinit.go 29.8 KB