aboutsummaryrefslogtreecommitdiff
path: root/src/cmd
diff options
context:
space:
mode:
Diffstat (limited to 'src/cmd')
-rw-r--r--src/cmd/compile/internal/noder/writer.go12
-rw-r--r--src/cmd/compile/testdata/script/issue70173.txt23
2 files changed, 34 insertions, 1 deletions
diff --git a/src/cmd/compile/internal/noder/writer.go b/src/cmd/compile/internal/noder/writer.go
index 564087d912..f4b02f279d 100644
--- a/src/cmd/compile/internal/noder/writer.go
+++ b/src/cmd/compile/internal/noder/writer.go
@@ -3070,7 +3070,17 @@ func isPtrTo(from, to types2.Type) bool {
// hasFallthrough reports whether stmts ends in a fallthrough
// statement.
func hasFallthrough(stmts []syntax.Stmt) bool {
- last, ok := lastNonEmptyStmt(stmts).(*syntax.BranchStmt)
+ // From spec: the last non-empty statement may be a (possibly labeled) "fallthrough" statement
+ // Stripping (possible nested) labeled statement if any.
+ stmt := lastNonEmptyStmt(stmts)
+ for {
+ ls, ok := stmt.(*syntax.LabeledStmt)
+ if !ok {
+ break
+ }
+ stmt = ls.Stmt
+ }
+ last, ok := stmt.(*syntax.BranchStmt)
return ok && last.Tok == syntax.Fallthrough
}
diff --git a/src/cmd/compile/testdata/script/issue70173.txt b/src/cmd/compile/testdata/script/issue70173.txt
new file mode 100644
index 0000000000..20d4b4fcbe
--- /dev/null
+++ b/src/cmd/compile/testdata/script/issue70173.txt
@@ -0,0 +1,23 @@
+go run main.go
+! stdout .
+! stderr .
+
+-- main.go --
+
+package main
+
+func main() {
+ switch {
+ case true:
+ _:
+ fallthrough
+ default:
+ }
+ switch {
+ case true:
+ _:
+ _:
+ fallthrough
+ default:
+ }
+}