mirror of
https://github.com/imjasonh/nescript
synced 2026-07-14 11:36:40 +00:00
Analyzer: W0103 also fires on unused state-local variables
Previously the unused-variable warning only ran on globals. Now it walks \`state.locals\` too, so state-scoped variables that are declared and never read also emit W0103. Factored out to \`check_unused_var\` to share the \`_\`-prefix exemption and help text. https://claude.ai/code/session_01W6eQFStA66EuMKHUFo2rx3
This commit is contained in:
parent
b7c806523d
commit
3f87aa1e30
2 changed files with 53 additions and 18 deletions
|
|
@ -562,6 +562,31 @@ fn analyze_unused_variable_warning() {
|
|||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn analyze_unused_state_local_warning() {
|
||||
// State-local `bonus` is declared but never read — W0103 should fire.
|
||||
let (prog, diags) = parser::parse(
|
||||
r#"
|
||||
game "Test" { mapper: NROM }
|
||||
state Main {
|
||||
var bonus: u8 = 0
|
||||
on frame { wait_frame }
|
||||
}
|
||||
start Main
|
||||
"#,
|
||||
);
|
||||
assert!(diags.is_empty(), "parse errors: {diags:?}");
|
||||
let result = analyze(&prog.unwrap());
|
||||
assert!(
|
||||
result
|
||||
.diagnostics
|
||||
.iter()
|
||||
.any(|d| d.code == ErrorCode::W0103 && d.message.contains("bonus")),
|
||||
"expected W0103 for unused state-local 'bonus', got: {:?}",
|
||||
result.diagnostics
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn analyze_unused_variable_no_warning_when_read() {
|
||||
// `counter` is both written and read (in the `if` condition),
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue