]> Cypherpunks repositories - gostls13.git/commit
go/types, types2: typecheck cases even if switch expression is invalid
authorRobert Griesemer <gri@golang.org>
Thu, 13 Jun 2024 16:29:22 +0000 (09:29 -0700)
committerGopher Robot <gobot@golang.org>
Thu, 13 Jun 2024 20:48:17 +0000 (20:48 +0000)
commit69e7b2bcd61e1d318c51e82a5514b21cbdb2dbc5
tree3f53b6192dbae4369b12677a139421e43de7d79d
parentdbe03e4831206d7311e4423c3a988fc48beda2bd
go/types, types2: typecheck cases even if switch expression is invalid

Rather than returning right away when the switch expression is invalid,
continue type checking the type switch case.

The code was already written to be able to deal with an invalid switch
expression but it returned early nevertheless. Remove the early return
and rewrite the switch expression test slightly to better control the
scope of the x operand, leading to cleaner code.

In the process replace a tricky use of the x operand with a use of the
sx operand (plus guard, since sx may be nil if invalid).

Fixes #67962.

Change-Id: I1dc08d10078753c68449637622beb4018ed23803
Reviewed-on: https://go-review.googlesource.com/c/go/+/592555
Reviewed-by: Robert Findley <rfindley@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Robert Griesemer <gri@google.com>
Auto-Submit: Robert Griesemer <gri@google.com>
src/cmd/compile/internal/types2/stmt.go
src/go/types/stmt.go
src/internal/types/testdata/fixedbugs/issue67962.go [new file with mode: 0644]