fix: improve error message for bare 'run' expressions at top level

When users write `run main() with {}` at top level instead of
`let _ = run main() with {}`, provide a helpful error message
explaining the correct syntax instead of the generic "Expected
declaration" error.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
2026-02-16 23:40:15 -05:00
parent 52e3876b81
commit bc60f1c8f1

View File

@@ -244,6 +244,7 @@ impl Parser {
TokenKind::Let => Ok(Declaration::Let(self.parse_let_decl(visibility, doc)?)), TokenKind::Let => Ok(Declaration::Let(self.parse_let_decl(visibility, doc)?)),
TokenKind::Trait => Ok(Declaration::Trait(self.parse_trait_decl(visibility, doc)?)), TokenKind::Trait => Ok(Declaration::Trait(self.parse_trait_decl(visibility, doc)?)),
TokenKind::Impl => Ok(Declaration::Impl(self.parse_impl_decl()?)), TokenKind::Impl => Ok(Declaration::Impl(self.parse_impl_decl()?)),
TokenKind::Run => Err(self.error("Bare 'run' expressions are not allowed at top level. Use 'let _ = run ...' or 'let result = run ...'")),
_ => Err(self.error("Expected declaration (fn, effect, handler, type, trait, impl, or let)")), _ => Err(self.error("Expected declaration (fn, effect, handler, type, trait, impl, or let)")),
} }
} }