]> Cypherpunks.ru repositories - gostls13.git/commit
cmd/compile: do branch/label checks only once
authorRobert Griesemer <gri@golang.org>
Sat, 25 Jun 2022 02:11:52 +0000 (19:11 -0700)
committerRobert Griesemer <gri@golang.org>
Sun, 26 Jun 2022 00:21:33 +0000 (00:21 +0000)
commit666d736ecb8afbe1aeb1d15f3958b70af2173510
tree3e03f662349ba7e5ae55ee38afe05b64d2d92a54
parent6b309be7ab7c17beb77c6e40b258278e7454d919
cmd/compile: do branch/label checks only once

The previous change implemented the missing fallthrough checking
in the parser. Therefore we can now disable the duplicate check
in the type checker:

- rename (types2.Config.)IngoreLabels to IgnoreBranches to more
  accurately reflect its functionality

- now also ignore break/continue/fallthroughs, not just labels

The IgnoreBranches flag only exists for types2, for use with
the compiler. There's no need to port this code to go/types.

Note: An alternative (and perhaps better) approach would be
to not use the the parser's CheckBranches mode and instead
enable (i.e. not disable) the branch/label checking in the
type checker. However, this requires a bit more work because
the type checker's error messages about goto's jumping over
variables don't have access to the variable names, which are
desired in the error messages.

Fixes #51456.

Change-Id: Ib2e71e811d4e84e4895b729646e879fd43b12dcd
Reviewed-on: https://go-review.googlesource.com/c/go/+/414135
Reviewed-by: Ian Lance Taylor <iant@google.com>
Reviewed-by: Robert Griesemer <gri@google.com>
src/cmd/compile/internal/noder/irgen.go
src/cmd/compile/internal/noder/noder.go
src/cmd/compile/internal/types2/api.go
src/cmd/compile/internal/types2/stmt.go