mirror of
https://github.com/AleoHQ/leo.git
synced 2024-11-13 08:47:17 +03:00
Parse empty return statement as a unit expression
This commit is contained in:
parent
6789bc8aae
commit
34fa2cb2c6
@ -116,8 +116,13 @@ impl ParserContext<'_> {
|
||||
/// Returns a [`ReturnStatement`] AST node if the next tokens represent a return statement.
|
||||
fn parse_return_statement(&mut self) -> Result<ReturnStatement> {
|
||||
let start = self.expect(&Token::Return)?;
|
||||
let expression = self.parse_expression()?;
|
||||
self.expect(&Token::Semicolon)?;
|
||||
let expression = match self.token.token {
|
||||
Token::Semicolon => {
|
||||
let span = self.expect(&Token::Semicolon)?;
|
||||
Expression::Unit(UnitExpression { span })
|
||||
}
|
||||
_ => self.parse_expression()?,
|
||||
};
|
||||
let span = start + expression.span();
|
||||
Ok(ReturnStatement { span, expression })
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user