Diagnostic for invalid number of parameters
This commit is contained in:
parent
6bb8139f40
commit
5f9c32874a
|
@ -200,6 +200,12 @@ namespace Upsilon.Binder
|
||||||
{
|
{
|
||||||
var variableExpression =(BoundVariableExpression) expression;
|
var variableExpression =(BoundVariableExpression) expression;
|
||||||
var function = (FunctionVariableSymbol)variableExpression.Variable.VariableSymbol;
|
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)
|
if (!function.IsBound)
|
||||||
{
|
{
|
||||||
Scope = new BoundScope(Scope);
|
Scope = new BoundScope(Scope);
|
||||||
|
|
|
@ -18,7 +18,7 @@ namespace Upsilon.Parser
|
||||||
OpenParenthesis = openParenthesis;
|
OpenParenthesis = openParenthesis;
|
||||||
Parameters = parameters;
|
Parameters = parameters;
|
||||||
CloseParenthesis = closeParenthesis;
|
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;
|
public override SyntaxKind Kind => SyntaxKind.FunctionCallExpression;
|
||||||
|
|
|
@ -202,15 +202,15 @@ namespace Upsilon.Parser
|
||||||
var functionToken = MatchToken(SyntaxKind.FunctionKeyword);
|
var functionToken = MatchToken(SyntaxKind.FunctionKeyword);
|
||||||
var openParenthesis = MatchToken(SyntaxKind.OpenParenthesis);
|
var openParenthesis = MatchToken(SyntaxKind.OpenParenthesis);
|
||||||
var variableBuilder = ImmutableArray.CreateBuilder<IdentifierToken>();
|
var variableBuilder = ImmutableArray.CreateBuilder<IdentifierToken>();
|
||||||
IdentifierToken lastIdentifier = null;
|
SyntaxToken current = null;
|
||||||
while (Current.Kind != SyntaxKind.CloseParenthesis)
|
while (Current.Kind != SyntaxKind.CloseParenthesis)
|
||||||
{
|
{
|
||||||
var variableIdentifier = (IdentifierToken)MatchToken(SyntaxKind.Identifier);
|
if (Current == current)
|
||||||
if (lastIdentifier == variableIdentifier)
|
|
||||||
{
|
{
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
lastIdentifier = variableIdentifier;
|
current = Current;
|
||||||
|
var variableIdentifier = (IdentifierToken)MatchToken(SyntaxKind.Identifier);
|
||||||
variableBuilder.Add(variableIdentifier);
|
variableBuilder.Add(variableIdentifier);
|
||||||
if (Current.Kind == SyntaxKind.Comma)
|
if (Current.Kind == SyntaxKind.Comma)
|
||||||
NextToken();
|
NextToken();
|
||||||
|
|
Loading…
Reference in New Issue