typecheck return types

This commit is contained in:
2026-03-17 17:11:14 +01:00
parent 664a51c88d
commit 4154901339
7 changed files with 72 additions and 50 deletions

View File

@@ -41,7 +41,10 @@ pub enum Stmt {
body: Box<Stmt>,
exported: bool,
},
Return(Expr),
Return {
expr: Expr,
keyword: Token,
},
Break,
Continue,
Extern(Token),
@@ -262,7 +265,11 @@ impl Parser {
} else if self.match_token(&[TokenType::KeywordFor]) {
self.for_statement()
} else if self.match_token(&[TokenType::KeywordReturn]) {
Ok(Stmt::Return(self.expression()?))
let keyword = self.previous().clone();
Ok(Stmt::Return {
expr: self.expression()?,
keyword,
})
} else if self.match_token(&[TokenType::KeywordBreak]) {
Ok(Stmt::Break)
} else if self.match_token(&[TokenType::KeywordContinue]) {