Fix function invocation stack underflow
This commit is contained in:
@@ -1225,18 +1225,34 @@ impl<'a> Parser<'a> {
|
||||
// Need to capture return span
|
||||
let ret_start_span = Self::token_to_span(¤t_token);
|
||||
self.assign_next()?;
|
||||
let expression = self.expression()?.ok_or(Error::UnexpectedEOF)?;
|
||||
|
||||
let expr = if token_matches!(
|
||||
self.current_token.as_ref().ok_or(Error::UnexpectedEOF)?,
|
||||
TokenType::Symbol(Symbol::Semicolon)
|
||||
) {
|
||||
// rewind 1 token so we can check for the semicolon at the bottom of this function.
|
||||
self.tokenizer.seek(SeekFrom::Current(-1))?;
|
||||
None
|
||||
} else {
|
||||
Some(self.expression()?.ok_or(Error::UnexpectedEOF)?)
|
||||
};
|
||||
|
||||
let ret_span = Span {
|
||||
start_line: ret_start_span.start_line,
|
||||
start_col: ret_start_span.start_col,
|
||||
end_line: expression.span.end_line,
|
||||
end_col: expression.span.end_col,
|
||||
end_line: expr
|
||||
.as_ref()
|
||||
.map(|e| e.span.end_line)
|
||||
.unwrap_or(ret_start_span.end_line),
|
||||
end_col: expr
|
||||
.as_ref()
|
||||
.map(|e| e.span.end_col)
|
||||
.unwrap_or(ret_start_span.end_col),
|
||||
};
|
||||
|
||||
let return_expr = Spanned {
|
||||
span: ret_span,
|
||||
node: Expression::Return(boxed!(expression)),
|
||||
node: Expression::Return(expr.map(Box::new)),
|
||||
};
|
||||
expressions.push(return_expr);
|
||||
|
||||
|
||||
@@ -381,7 +381,7 @@ pub enum Expression<'a> {
|
||||
MethodCall(Spanned<MethodCallExpression<'a>>),
|
||||
Negation(Box<Spanned<Expression<'a>>>),
|
||||
Priority(Box<Spanned<Expression<'a>>>),
|
||||
Return(Box<Spanned<Expression<'a>>>),
|
||||
Return(Option<Box<Spanned<Expression<'a>>>>),
|
||||
Syscall(Spanned<SysCall<'a>>),
|
||||
Ternary(Spanned<TernaryExpression<'a>>),
|
||||
Variable(Spanned<Cow<'a, str>>),
|
||||
@@ -409,7 +409,15 @@ impl<'a> std::fmt::Display for Expression<'a> {
|
||||
Expression::MethodCall(e) => write!(f, "{}", e),
|
||||
Expression::Negation(e) => write!(f, "(-{})", e),
|
||||
Expression::Priority(e) => write!(f, "({})", e),
|
||||
Expression::Return(e) => write!(f, "(return {})", e),
|
||||
Expression::Return(e) => write!(
|
||||
f,
|
||||
"(return {})",
|
||||
if let Some(e) = e {
|
||||
e.to_string()
|
||||
} else {
|
||||
"".to_string()
|
||||
}
|
||||
),
|
||||
Expression::Syscall(e) => write!(f, "{}", e),
|
||||
Expression::Ternary(e) => write!(f, "{}", e),
|
||||
Expression::Variable(id) => write!(f, "{}", id),
|
||||
|
||||
Reference in New Issue
Block a user