diff options
Diffstat (limited to 'typecheck.c')
| -rw-r--r-- | typecheck.c | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/typecheck.c b/typecheck.c index 1ab20177..0530ff7b 100644 --- a/typecheck.c +++ b/typecheck.c @@ -921,7 +921,17 @@ type_t *get_type(env_t *env, ast_t *ast) env_t *block_env = fresh_scope(env); for (ast_list_t *stmt = block->statements; stmt; stmt = stmt->next) { + prebind_statement(block_env, stmt->ast); + } + for (ast_list_t *stmt = block->statements; stmt; stmt = stmt->next) { bind_statement(block_env, stmt->ast); + if (stmt->next) { // Check for unreachable code: + if (stmt->ast->tag == Return) + code_err(stmt->ast, "This statement will always return, so the rest of the code in this block is unreachable!"); + type_t *statement_type = get_type(block_env, stmt->ast); + if (statement_type && statement_type->tag == AbortType && stmt->next) + code_err(stmt->ast, "This statement will always abort, so the rest of the code in this block is unreachable!"); + } } return get_type(block_env, last->ast); } |
