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