1
0
Fork 0
mirror of https://github.com/imjasonh/nescript synced 2026-07-08 08:55:38 +00:00

Parser: E0505 error on multiple 'start' declarations

Previously a second \`start X\` statement silently overrode the first.
Now emits E0505 at parse time.

https://claude.ai/code/session_01W6eQFStA66EuMKHUFo2rx3
This commit is contained in:
Claude 2026-04-12 10:59:06 +00:00
parent 814cbe54bd
commit 4e05c008ce
No known key found for this signature in database
3 changed files with 24 additions and 1 deletions

View file

@ -39,7 +39,6 @@ pub enum ErrorCode {
E0502, // undefined variable
E0503, // undefined function
E0504, // missing start declaration
#[allow(dead_code)]
E0505, // multiple start declarations
// W01xx: Warnings

View file

@ -163,8 +163,16 @@ impl Parser {
on_frame = Some(self.parse_on_frame()?);
}
TokenKind::KwStart => {
let kw_span = self.current_span();
self.advance();
let (name, _) = self.expect_ident()?;
if start_state.is_some() {
return Err(Diagnostic::error(
ErrorCode::E0505,
"multiple 'start' declarations",
kw_span,
));
}
start_state = Some(name);
}
_ => {

View file

@ -665,6 +665,22 @@ fn parse_mmc3_mapper() {
assert_eq!(prog.game.mapper, Mapper::MMC3);
}
#[test]
fn parse_multiple_start_declarations_error() {
let src = r#"
game "Test" { mapper: NROM }
state A { on frame { wait_frame } }
state B { on frame { wait_frame } }
start A
start B
"#;
let errors = parse_err(src);
assert!(
errors.contains(&crate::errors::ErrorCode::E0505),
"duplicate start should produce E0505, got: {errors:?}"
);
}
#[test]
fn parse_on_scanline_handler() {
let src = r#"