mirror of
https://github.com/imjasonh/nescript
synced 2026-07-18 06:36:57 +00:00
Analyzer: E0203 for bare return in typed function
A \`return\` with no value inside a function that has a declared return type is an error — the caller expects a value. Previously it compiled silently and the callee returned whatever was in A from the last computation. https://claude.ai/code/session_01W6eQFStA66EuMKHUFo2rx3
This commit is contained in:
parent
2fd3a6e545
commit
c10251338d
2 changed files with 31 additions and 1 deletions
|
|
@ -601,6 +601,26 @@ fn analyze_loop_with_break_ok() {
|
|||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn analyze_bare_return_from_typed_fn_errors() {
|
||||
// A `return` with no value inside a function that has a declared
|
||||
// return type should produce E0203.
|
||||
let errors = analyze_errors(
|
||||
r#"
|
||||
game "Test" { mapper: NROM }
|
||||
fun get_five() -> u8 {
|
||||
return
|
||||
}
|
||||
on frame { wait_frame }
|
||||
start Main
|
||||
"#,
|
||||
);
|
||||
assert!(
|
||||
errors.contains(&ErrorCode::E0203),
|
||||
"bare return from typed fn should produce E0203, got: {errors:?}"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn analyze_return_value_from_void_fn() {
|
||||
let errors = analyze_errors(
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue