Diagnostic for invalid number of parameters

This commit is contained in:
Deukhoofd 2018-11-25 20:55:36 +01:00
parent 6bb8139f40
commit 5f9c32874a
No known key found for this signature in database
GPG Key ID: B4C087AC81641654
3 changed files with 11 additions and 5 deletions

View File

@ -200,6 +200,12 @@ namespace Upsilon.Binder
{
var variableExpression =(BoundVariableExpression) expression;
var function = (FunctionVariableSymbol)variableExpression.Variable.VariableSymbol;
if (function.Parameters.Length != parameters.Count)
{
_diagnostics.LogError($"Invalid number of parameters for function '{function.Name}'. " +
$"Expected '{function.Parameters.Length}', got '{parameters.Count}'", e.Span);
return new BoundLiteralExpression(new ScriptNull(), e.Span);
}
if (!function.IsBound)
{
Scope = new BoundScope(Scope);

View File

@ -18,7 +18,7 @@ namespace Upsilon.Parser
OpenParenthesis = openParenthesis;
Parameters = parameters;
CloseParenthesis = closeParenthesis;
Span = new TextSpan(Identifier.Span.Start, CloseParenthesis.Span.End - Identifier.Span.End);
Span = new TextSpan(Identifier.Span.Start, CloseParenthesis.Span.End - Identifier.Span.Start);
}
public override SyntaxKind Kind => SyntaxKind.FunctionCallExpression;

View File

@ -202,15 +202,15 @@ namespace Upsilon.Parser
var functionToken = MatchToken(SyntaxKind.FunctionKeyword);
var openParenthesis = MatchToken(SyntaxKind.OpenParenthesis);
var variableBuilder = ImmutableArray.CreateBuilder<IdentifierToken>();
IdentifierToken lastIdentifier = null;
SyntaxToken current = null;
while (Current.Kind != SyntaxKind.CloseParenthesis)
{
var variableIdentifier = (IdentifierToken)MatchToken(SyntaxKind.Identifier);
if (lastIdentifier == variableIdentifier)
if (Current == current)
{
break;
}
lastIdentifier = variableIdentifier;
current = Current;
var variableIdentifier = (IdentifierToken)MatchToken(SyntaxKind.Identifier);
variableBuilder.Add(variableIdentifier);
if (Current.Kind == SyntaxKind.Comma)
NextToken();