compiler: call error_statement for fallthrough in last case
It is possible to do this check in backend, by walking the
block and check whether the last statement is a goto. But it
seems easier to do it in the frontend, where it can simply use
is_fallthrough.
Change-Id: Icd61c52c96a408f7e00566cb7b232848cd449e25
Reviewed-on: https://go-review.googlesource.com/63690
Reviewed-by: Ian Lance Taylor <iant@golang.org>
diff --git a/go/statements.cc b/go/statements.cc
index eb370f8..bea57cd 100644
--- a/go/statements.cc
+++ b/go/statements.cc
@@ -3707,6 +3707,12 @@
std::vector<Bexpression*> cases;
Bstatement* stat = p->get_backend(context, break_label, &case_constants,
&cases);
+ // The final clause can't fall through.
+ if (i == c - 1 && p->is_fallthrough())
+ {
+ go_assert(saw_errors());
+ stat = context->backend()->error_statement();
+ }
(*all_cases)[i].swap(cases);
(*all_statements)[i] = stat;
}