From d5ff13335f2377f799e4368a5539dcb72ed96b96 Mon Sep 17 00:00:00 2001 From: Delyan Angelov Date: Tue, 26 Aug 2025 14:27:30 +0300 Subject: [PATCH] checker: relax the "unreachable code after a @[noreturn] call" error to a warning to reduce prototyping friction (#25173) --- vlib/v/checker/return.v | 2 +- .../tests/noreturn_with_non_empty_loop_at_end.out | 12 ++++++------ vlib/v/checker/tests/noreturn_with_return.out | 12 ++++++------ ...eturn_without_loop_or_another_noreturn_at_end.out | 12 ++++++------ 4 files changed, 19 insertions(+), 19 deletions(-) diff --git a/vlib/v/checker/return.v b/vlib/v/checker/return.v index 966fddb47..bf947dfd8 100644 --- a/vlib/v/checker/return.v +++ b/vlib/v/checker/return.v @@ -328,7 +328,7 @@ fn (mut c Checker) find_unreachable_statements_after_noreturn_calls(stmts []ast. if stmt is ast.ExprStmt { if stmt.expr is ast.CallExpr { if prev_stmt_was_noreturn_call { - c.error('unreachable code after a @[noreturn] call', stmt.pos) + c.warn('unreachable code after a @[noreturn] call', stmt.pos) return } prev_stmt_was_noreturn_call = stmt.expr.is_noreturn diff --git a/vlib/v/checker/tests/noreturn_with_non_empty_loop_at_end.out b/vlib/v/checker/tests/noreturn_with_non_empty_loop_at_end.out index 882b9ed33..8c8181495 100644 --- a/vlib/v/checker/tests/noreturn_with_non_empty_loop_at_end.out +++ b/vlib/v/checker/tests/noreturn_with_non_empty_loop_at_end.out @@ -1,3 +1,9 @@ +vlib/v/checker/tests/noreturn_with_non_empty_loop_at_end.vv:18:2: warning: unreachable code after a @[noreturn] call + 16 | eprintln('start') + 17 | abc() + 18 | eprintln('done') + | ~~~~~~~~~~~~~~~~ + 19 | } vlib/v/checker/tests/noreturn_with_non_empty_loop_at_end.vv:4:6: error: @[noreturn] functions should end with a call to another @[noreturn] function, or with an infinite `for {}` loop 2 | fn another() { 3 | eprintln(@FN) @@ -5,9 +11,3 @@ vlib/v/checker/tests/noreturn_with_non_empty_loop_at_end.vv:4:6: error: @[noretu | ^ 5 | break 6 | } -vlib/v/checker/tests/noreturn_with_non_empty_loop_at_end.vv:18:2: error: unreachable code after a @[noreturn] call - 16 | eprintln('start') - 17 | abc() - 18 | eprintln('done') - | ~~~~~~~~~~~~~~~~ - 19 | } diff --git a/vlib/v/checker/tests/noreturn_with_return.out b/vlib/v/checker/tests/noreturn_with_return.out index 0164afc38..e1f04cb90 100644 --- a/vlib/v/checker/tests/noreturn_with_return.out +++ b/vlib/v/checker/tests/noreturn_with_return.out @@ -1,3 +1,9 @@ +vlib/v/checker/tests/noreturn_with_return.vv:18:2: warning: unreachable code after a @[noreturn] call + 16 | eprintln('start') + 17 | abc() + 18 | eprintln('done') + | ~~~~~~~~~~~~~~~~ + 19 | } vlib/v/checker/tests/noreturn_with_return.vv:2:1: error: [noreturn] functions cannot use return statements 1 | @[noreturn] 2 | fn another() { @@ -11,9 +17,3 @@ vlib/v/checker/tests/noreturn_with_return.vv:6:2: error: @[noreturn] functions s | ~~~~~~ 7 | } 8 | -vlib/v/checker/tests/noreturn_with_return.vv:18:2: error: unreachable code after a @[noreturn] call - 16 | eprintln('start') - 17 | abc() - 18 | eprintln('done') - | ~~~~~~~~~~~~~~~~ - 19 | } diff --git a/vlib/v/checker/tests/noreturn_without_loop_or_another_noreturn_at_end.out b/vlib/v/checker/tests/noreturn_without_loop_or_another_noreturn_at_end.out index ec14b5e79..f65373b7d 100644 --- a/vlib/v/checker/tests/noreturn_without_loop_or_another_noreturn_at_end.out +++ b/vlib/v/checker/tests/noreturn_without_loop_or_another_noreturn_at_end.out @@ -1,3 +1,9 @@ +vlib/v/checker/tests/noreturn_without_loop_or_another_noreturn_at_end.vv:15:2: warning: unreachable code after a @[noreturn] call + 13 | eprintln('start') + 14 | abc() + 15 | eprintln('done') + | ~~~~~~~~~~~~~~~~ + 16 | } vlib/v/checker/tests/noreturn_without_loop_or_another_noreturn_at_end.vv:3:2: error: @[noreturn] functions should end with a call to another @[noreturn] function, or with an infinite `for {}` loop 1 | @[noreturn] 2 | fn another() { @@ -5,9 +11,3 @@ vlib/v/checker/tests/noreturn_without_loop_or_another_noreturn_at_end.vv:3:2: er | ~~~~~~~~~~~~~ 4 | } 5 | -vlib/v/checker/tests/noreturn_without_loop_or_another_noreturn_at_end.vv:15:2: error: unreachable code after a @[noreturn] call - 13 | eprintln('start') - 14 | abc() - 15 | eprintln('done') - | ~~~~~~~~~~~~~~~~ - 16 | } -- 2.39.5