From 14ce6d8ed8864f9283c55fdd0d9a9cc2039470b4 Mon Sep 17 00:00:00 2001 From: gingerBill Date: Wed, 13 May 2020 23:09:38 +0100 Subject: [PATCH] Fix #632 behaviour --- src/check_stmt.cpp | 22 +++++++++++++++++++--- 1 file 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 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 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 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); } }