Handle empty return statements
This commit is contained in:
parent
cc029d0689
commit
cefe48cb4b
|
@ -509,6 +509,9 @@ namespace Upsilon.Binder
|
||||||
|
|
||||||
private BoundStatement BindReturnStatement(ReturnStatementSyntax e)
|
private BoundStatement BindReturnStatement(ReturnStatementSyntax e)
|
||||||
{
|
{
|
||||||
|
if (e.Expression == null)
|
||||||
|
return new BoundReturnStatement(null, e.Span);
|
||||||
|
|
||||||
var expression = BindExpression(e.Expression);
|
var expression = BindExpression(e.Expression);
|
||||||
if (expression.Type != Type.Unknown && expression.Type != Type.Unknown &&
|
if (expression.Type != Type.Unknown && expression.Type != Type.Unknown &&
|
||||||
Scope.ReturnType != Type.Unknown && Scope.ReturnType != Type.Nil)
|
Scope.ReturnType != Type.Unknown && Scope.ReturnType != Type.Nil)
|
||||||
|
|
|
@ -423,7 +423,7 @@ namespace Upsilon.Evaluator
|
||||||
|
|
||||||
private void EvaluateReturnStatement(BoundReturnStatement b)
|
private void EvaluateReturnStatement(BoundReturnStatement b)
|
||||||
{
|
{
|
||||||
_returnValue = EvaluateExpression(b.Expression);
|
_returnValue = b.Expression == null ? null : EvaluateExpression(b.Expression);
|
||||||
_lastValue = _returnValue;
|
_lastValue = _returnValue;
|
||||||
HasReturned = true;
|
HasReturned = true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -283,7 +283,9 @@ namespace Upsilon.Parser
|
||||||
private StatementSyntax ParseReturnStatement()
|
private StatementSyntax ParseReturnStatement()
|
||||||
{
|
{
|
||||||
var returnToken = MatchToken(SyntaxKind.ReturnKeyword);
|
var returnToken = MatchToken(SyntaxKind.ReturnKeyword);
|
||||||
var expression = ParseExpression();
|
ExpressionSyntax expression = null;
|
||||||
|
if (Current.Kind != SyntaxKind.EndKeyword)
|
||||||
|
expression = ParseExpression();
|
||||||
return new ReturnStatementSyntax(returnToken, expression);
|
return new ReturnStatementSyntax(returnToken, expression);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -9,7 +9,9 @@ namespace Upsilon.Parser
|
||||||
{
|
{
|
||||||
ReturnToken = returnToken;
|
ReturnToken = returnToken;
|
||||||
Expression = expression;
|
Expression = expression;
|
||||||
Span = new TextSpan(returnToken.Span.Start, expression.Span.End - returnToken.Span.Start);
|
var end = returnToken.Span.End;
|
||||||
|
if (expression != null) end = expression.Span.End;
|
||||||
|
Span = new TextSpan(returnToken.Span.Start, end - returnToken.Span.Start);
|
||||||
}
|
}
|
||||||
|
|
||||||
public SyntaxToken ReturnToken { get; }
|
public SyntaxToken ReturnToken { get; }
|
||||||
|
|
Loading…
Reference in New Issue