aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/compile/internal/typecheck/typecheck.go
diff options
context:
space:
mode:
authorMatthew Dempsky <mdempsky@google.com>2021-01-05 03:28:06 -0800
committerMatthew Dempsky <mdempsky@google.com>2021-01-05 14:03:51 +0000
commit9aa950c40789223d9e8df7d1ec657cd313e6c7aa (patch)
tree52fc185da6c7a2e831aaef268d4f15d8d01cf946 /src/cmd/compile/internal/typecheck/typecheck.go
parenteb626409d152caabac418eccbe86b49d1fc6a6f5 (diff)
downloadgo-9aa950c40789223d9e8df7d1ec657cd313e6c7aa.tar.gz
go-9aa950c40789223d9e8df7d1ec657cd313e6c7aa.zip
[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>
Diffstat (limited to 'src/cmd/compile/internal/typecheck/typecheck.go')
-rw-r--r--src/cmd/compile/internal/typecheck/typecheck.go13
1 files changed, 8 insertions, 5 deletions
diff --git a/src/cmd/compile/internal/typecheck/typecheck.go b/src/cmd/compile/internal/typecheck/typecheck.go
index 981f4ef1d6..c3a5a3c40f 100644
--- a/src/cmd/compile/internal/typecheck/typecheck.go
+++ b/src/cmd/compile/internal/typecheck/typecheck.go
@@ -1612,6 +1612,14 @@ func checklvalue(n ir.Node, verb string) {
}
func checkassign(stmt ir.Node, n ir.Node) {
+ // have already complained about n being invalid
+ if n.Type() == nil {
+ if base.Errors() == 0 {
+ base.Fatalf("expected an error about %v", n)
+ }
+ return
+ }
+
// Variables declared in ORANGE are assigned on every iteration.
if !ir.DeclaredBy(n, stmt) || stmt.Op() == ir.ORANGE {
r := ir.OuterValue(n)
@@ -1633,11 +1641,6 @@ func checkassign(stmt ir.Node, n ir.Node) {
return
}
- // have already complained about n being invalid
- if n.Type() == nil {
- return
- }
-
switch {
case n.Op() == ir.ODOT && n.(*ir.SelectorExpr).X.Op() == ir.OINDEXMAP:
base.Errorf("cannot assign to struct field %v in map", n)