[dev.regabi] cmd/compile: make ir.OuterValue safer

For OINDEX expressions, ir.OuterValue depends on knowing the indexee's
type. Rather than silently acting as though it's not an array, make it
loudly fail.

The only code that needs to be fixed to support this is checkassign
during typechecking, which needs to avoid calling ir.OuterValue now if
typechecking the assigned operand already failed.

Passes toolstash -cmp.

Change-Id: I935cae0dacc837202bc6b63164dc2f0a6fde005c
Reviewed-on: https://go-review.googlesource.com/c/go/+/281539
Trust: Matthew Dempsky <mdempsky@google.com>
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Cuong Manh Le <cuong.manhle.vn@gmail.com>
This commit is contained in:
Matthew Dempsky 2021-01-05 03:28:06 -08:00
parent eb626409d1
commit 9aa950c407
2 changed files with 12 additions and 6 deletions

View file

@ -568,7 +568,10 @@ func OuterValue(n Node) Node {
continue
case OINDEX:
nn := nn.(*IndexExpr)
if nn.X.Type() != nil && nn.X.Type().IsArray() {
if nn.X.Type() == nil {
base.Fatalf("OuterValue needs type for %v", nn.X)
}
if nn.X.Type().IsArray() {
n = nn.X
continue
}