]> Cypherpunks repositories - gostls13.git/commit
cmd/compile: fix crash on invalid struct literal
authorDaniel Martí <mvdan@mvdan.cc>
Tue, 17 Jul 2018 13:38:52 +0000 (14:38 +0100)
committerDaniel Martí <mvdan@mvdan.cc>
Wed, 18 Jul 2018 20:32:04 +0000 (20:32 +0000)
commitba6974fdc3ce96acc259055a051bbfcbabce2be4
treed988ed278f6e84b18d2e0c10c17487a161c0a65e
parentee198df4cdc2e49c7376f99d9d3081da6ebae836
cmd/compile: fix crash on invalid struct literal

If one tries to use promoted fields in a struct literal, the compiler
errors correctly. However, if the embedded fields are of struct pointer
type, the field.Type.Sym.Name expression below panics.

This is because field.Type.Sym is nil in that case. We can simply use
field.Sym.Name in this piece of code though, as it only concerns
embedded fields, in which case what we are after is the field name.

Added a test mirroring fixedbugs/issue23609.go, but with pointer types.

Fixes #26416.

Change-Id: Ia46ce62995c9e1653f315accb99d592aff2f285e
Reviewed-on: https://go-review.googlesource.com/124395
Run-TryBot: Daniel Martí <mvdan@mvdan.cc>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Emmanuel Odeke <emm.odeke@gmail.com>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
src/cmd/compile/internal/gc/typecheck.go
test/fixedbugs/issue26416.go [new file with mode: 0644]