aboutsummaryrefslogtreecommitdiff
path: root/src/check_stmt.cpp
diff options
context:
space:
mode:
authorgingerBill <bill@gingerbill.org>2020-05-13 23:09:38 +0100
committergingerBill <bill@gingerbill.org>2020-05-13 23:09:38 +0100
commit14ce6d8ed8864f9283c55fdd0d9a9cc2039470b4 (patch)
tree432c1fe8feafbe6c2b5c0c705ccd463466108092 /src/check_stmt.cpp
parent2630e9ced153ae8806053cf1662d4b4e4fbcfc63 (diff)
Fix #632 behaviour
Diffstat (limited to 'src/check_stmt.cpp')
-rw-r--r--src/check_stmt.cpp22
1 files changed, 19 insertions, 3 deletions
diff --git a/src/check_stmt.cpp b/src/check_stmt.cpp
index df6d3685c..3e84db279 100644
--- a/src/check_stmt.cpp
+++ b/src/check_stmt.cpp
@@ -17,6 +17,18 @@ void check_stmt_list(CheckerContext *ctx, Array<Ast *> const &stmts, u32 flags)
}
max--;
}
+ isize max_non_constant_declaration = stmts.count;
+ for (isize i = stmts.count-1; i >= 0; i--) {
+ if (stmts[i]->kind == Ast_EmptyStmt) {
+ // Okay
+ } else if (stmts[i]->kind == Ast_ValueDecl && !stmts[i]->ValueDecl.is_mutable) {
+ // Okay
+ } else {
+ break;
+ }
+ max_non_constant_declaration--;
+ }
+
for (isize i = 0; i < max; i++) {
Ast *n = stmts[i];
if (n->kind == Ast_EmptyStmt) {
@@ -27,10 +39,10 @@ void check_stmt_list(CheckerContext *ctx, Array<Ast *> const &stmts, u32 flags)
new_flags |= Stmt_FallthroughAllowed;
}
- if (i+1 < max) {
+ if (i+1 < max_non_constant_declaration) {
switch (n->kind) {
case Ast_ReturnStmt:
- error(n, "Statements after this 'return' are never execu");
+ error(n, "Statements after this 'return' are never executed");
break;
case Ast_BranchStmt:
@@ -47,7 +59,11 @@ bool check_is_terminating_list(Array<Ast *> const &stmts) {
// Iterate backwards
for (isize n = stmts.count-1; n >= 0; n--) {
Ast *stmt = stmts[n];
- if (stmt->kind != Ast_EmptyStmt) {
+ if (stmt->kind == Ast_EmptyStmt) {
+ // Okay
+ } else if (stmt->kind == Ast_ValueDecl && !stmt->ValueDecl.is_mutable) {
+ // Okay
+ } else {
return check_is_terminating(stmt);
}
}