diff --git a/Upsilon/Binder/Binder.cs b/Upsilon/Binder/Binder.cs index c19a147..de4b621 100644 --- a/Upsilon/Binder/Binder.cs +++ b/Upsilon/Binder/Binder.cs @@ -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); diff --git a/Upsilon/Parser/ExpressionSyntax/FunctionCallExpressionSyntax.cs b/Upsilon/Parser/ExpressionSyntax/FunctionCallExpressionSyntax.cs index 81fc2a1..76a7d3c 100644 --- a/Upsilon/Parser/ExpressionSyntax/FunctionCallExpressionSyntax.cs +++ b/Upsilon/Parser/ExpressionSyntax/FunctionCallExpressionSyntax.cs @@ -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; diff --git a/Upsilon/Parser/Parser.cs b/Upsilon/Parser/Parser.cs index 57c69de..4a4bfe7 100644 --- a/Upsilon/Parser/Parser.cs +++ b/Upsilon/Parser/Parser.cs @@ -202,15 +202,15 @@ namespace Upsilon.Parser var functionToken = MatchToken(SyntaxKind.FunctionKeyword); var openParenthesis = MatchToken(SyntaxKind.OpenParenthesis); var variableBuilder = ImmutableArray.CreateBuilder(); - 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();