47 lines
1.8 KiB
C#
47 lines
1.8 KiB
C#
using System.Collections.Immutable;
|
|
using Upsilon.BaseTypes;
|
|
|
|
namespace Upsilon.Binder.VariableSymbols
|
|
{
|
|
public class ScriptFunctionVariableSymbol : FunctionVariableSymbol
|
|
{
|
|
public ImmutableArray<VariableSymbol> Parameters { get; }
|
|
public bool IsBound { get; set; }
|
|
|
|
|
|
public ScriptFunctionVariableSymbol(string name, bool local, ImmutableArray<VariableSymbol> parameters, Type resultType)
|
|
: base(name, local, resultType)
|
|
{
|
|
Parameters = parameters;
|
|
}
|
|
|
|
public override (bool IsValid, string Error, BoundExpression WrongParameter) ValidateParameters(ImmutableArray<BoundExpression> callingParameters)
|
|
{
|
|
if (Parameters.Length != callingParameters.Length)
|
|
{
|
|
return (false,
|
|
$"Invalid number of parameters for function '{Name}'. Expected {Parameters.Length}, got {callingParameters.Length}",
|
|
null);
|
|
}
|
|
|
|
for (var i = 0; i < Parameters.Length; i++)
|
|
{
|
|
var functionParameter = Parameters[i];
|
|
var callingParameter = callingParameters[i];
|
|
if (functionParameter.Type != Type.Unknown &&
|
|
callingParameter.Type != Type.Unknown && callingParameter.Type != Type.Nil)
|
|
{
|
|
if (callingParameter.Type != functionParameter.Type)
|
|
{
|
|
return (false, $"Invalid type for function '{Name}' at parameter '{functionParameter.Name}'. " +
|
|
$"Expected type '{functionParameter.Type}', got '{callingParameter.Type}'",
|
|
callingParameter);
|
|
}
|
|
}
|
|
}
|
|
|
|
return (true, null, null);
|
|
}
|
|
|
|
}
|
|
} |