checker: relax the "unreachable code after a @[noreturn] call" error to a warning to reduce prototyping friction (#25173)

This commit is contained in:
Delyan Angelov 2025-08-26 14:27:30 +03:00 committed by GitHub
parent 8e9f2880a0
commit d5ff13335f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 19 additions and 19 deletions

View File

@ -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

View File

@ -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 | }

View File

@ -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 | }

View File

@ -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 | }