Better error messages for function parameter mismatch
This commit is contained in:
@@ -456,7 +456,10 @@ public sealed class TypeChecker
|
|||||||
|
|
||||||
if (expression.Parameters.Count != funcType.Parameters.Count)
|
if (expression.Parameters.Count != funcType.Parameters.Count)
|
||||||
{
|
{
|
||||||
throw new TypeCheckerException(Diagnostic.Error($"Function {funcType} expects {funcType.Parameters} but got {expression.Parameters.Count} parameters").At(expression.Expression).Build());
|
throw new TypeCheckerException(Diagnostic
|
||||||
|
.Error($"Function {funcType} expects {funcType.Parameters.Count} parameters but got {expression.Parameters.Count}")
|
||||||
|
.At(expression.Parameters.LastOrDefault(expression))
|
||||||
|
.Build());
|
||||||
}
|
}
|
||||||
|
|
||||||
var parameters = new List<ExpressionNode>();
|
var parameters = new List<ExpressionNode>();
|
||||||
@@ -468,7 +471,10 @@ public sealed class TypeChecker
|
|||||||
var parameterExpression = CheckExpression(parameter, expectedType);
|
var parameterExpression = CheckExpression(parameter, expectedType);
|
||||||
if (parameterExpression.Type != expectedType)
|
if (parameterExpression.Type != expectedType)
|
||||||
{
|
{
|
||||||
throw new TypeCheckerException(Diagnostic.Error($"Parameter {i + 1} does not match the type {expectedType} for function {funcType}").At(parameter).Build());
|
throw new TypeCheckerException(Diagnostic
|
||||||
|
.Error($"Parameter {i + 1} does not match the type {expectedType} for function {funcType}")
|
||||||
|
.At(parameter)
|
||||||
|
.Build());
|
||||||
}
|
}
|
||||||
|
|
||||||
parameters.Add(parameterExpression);
|
parameters.Add(parameterExpression);
|
||||||
@@ -489,6 +495,14 @@ public sealed class TypeChecker
|
|||||||
throw new TypeCheckerException(Diagnostic.Error($"Function {expression.Name} not found on struct {structType}").At(expression).Build());
|
throw new TypeCheckerException(Diagnostic.Error($"Function {expression.Name} not found on struct {structType}").At(expression).Build());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (expression.Parameters.Count != function.Type.Parameters.Count)
|
||||||
|
{
|
||||||
|
throw new TypeCheckerException(Diagnostic
|
||||||
|
.Error($"Function {function.Type} expects {function.Type.Parameters.Count} parameters but got {expression.Parameters.Count}")
|
||||||
|
.At(expression.Parameters.LastOrDefault(expression))
|
||||||
|
.Build());
|
||||||
|
}
|
||||||
|
|
||||||
var parameters = new List<ExpressionNode>();
|
var parameters = new List<ExpressionNode>();
|
||||||
for (var i = 0; i < expression.Parameters.Count; i++)
|
for (var i = 0; i < expression.Parameters.Count; i++)
|
||||||
{
|
{
|
||||||
@@ -498,7 +512,10 @@ public sealed class TypeChecker
|
|||||||
var parameterExpression = CheckExpression(parameter, expectedType);
|
var parameterExpression = CheckExpression(parameter, expectedType);
|
||||||
if (parameterExpression.Type != expectedType)
|
if (parameterExpression.Type != expectedType)
|
||||||
{
|
{
|
||||||
throw new TypeCheckerException(Diagnostic.Error($"Parameter {i + 1} does not match the type {expectedType} for function {function}").At(parameter).Build());
|
throw new TypeCheckerException(Diagnostic
|
||||||
|
.Error($"Parameter {i + 1} does not match the type {expectedType} for function {function}")
|
||||||
|
.At(parameter)
|
||||||
|
.Build());
|
||||||
}
|
}
|
||||||
|
|
||||||
parameters.Add(parameterExpression);
|
parameters.Add(parameterExpression);
|
||||||
|
|||||||
Reference in New Issue
Block a user