More fixes for function binding
This commit is contained in:
parent
87a533ac2b
commit
faaca91265
|
@ -88,6 +88,7 @@ namespace Upsilon.BaseTypes
|
|||
}
|
||||
}
|
||||
|
||||
/*
|
||||
internal class IgnoredUserDataTypeContainer : TypeContainer
|
||||
{
|
||||
public IgnoredUserDataTypeContainer() : base(BaseTypes.Type.Unknown)
|
||||
|
@ -98,7 +99,7 @@ namespace Upsilon.BaseTypes
|
|||
public IgnoredUserDataTypeContainer(string userData) : base(userData)
|
||||
{
|
||||
}
|
||||
}
|
||||
}*/
|
||||
|
||||
public class UndefinedUserDataTypeContainer : TypeContainer
|
||||
{
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
using Upsilon.BoundTypes;
|
||||
using Upsilon.Evaluator;
|
||||
using Upsilon.Text;
|
||||
|
||||
|
@ -8,9 +9,12 @@ namespace Upsilon.BaseTypes.UserData
|
|||
public GenericUserData(object obj)
|
||||
{
|
||||
Value = obj;
|
||||
_typeInfo = UserDataTypeHandler.GetTypeInfo(obj.GetType());
|
||||
var type = obj.GetType();
|
||||
_typeInfo = UserDataTypeHandler.GetTypeInfo(type);
|
||||
Type = new TypeContainer(_typeInfo.BoundTypeName);
|
||||
|
||||
}
|
||||
public override TypeContainer Type { get; } = new IgnoredUserDataTypeContainer();
|
||||
public override TypeContainer Type { get; }
|
||||
|
||||
private object Value { get; }
|
||||
private readonly UserDataType _typeInfo;
|
||||
|
|
|
@ -304,19 +304,14 @@ namespace Upsilon.Binder
|
|||
{
|
||||
returnType = internalFunction.GetResultType(parameters.ToArray());
|
||||
}
|
||||
else
|
||||
{
|
||||
//returnType = function.ResultType;
|
||||
}
|
||||
}
|
||||
|
||||
var (isValid, error, wrongParameter) = function.ValidateParameters(parameters.ToImmutable());
|
||||
var isValid = function.ValidateParameters(parameters.ToImmutable());
|
||||
if (!isValid)
|
||||
{
|
||||
var span = e.Span;
|
||||
if (wrongParameter != null)
|
||||
span = wrongParameter.Span;
|
||||
_diagnostics.LogError(error, span);
|
||||
_diagnostics.LogError(
|
||||
$"No valid function with name '{function.Name}' and parameter types {string.Join(", ", parameters.Select(x => $"'{x.Type}'"))} found",
|
||||
expression.Span);
|
||||
}
|
||||
}
|
||||
else if (resolved is UserDataVariableSymbol udSymbol)
|
||||
|
|
|
@ -14,7 +14,7 @@ namespace Upsilon.Binder.VariableSymbols
|
|||
{
|
||||
}
|
||||
|
||||
public abstract (bool IsValid, string Error, BoundExpression WrongParameter) ValidateParameters(
|
||||
public abstract bool ValidateParameters(
|
||||
ImmutableArray<BoundExpression> callingParameters);
|
||||
|
||||
public FunctionVariableSymbolOption GetFirstValid(TypeContainer[] types)
|
||||
|
|
|
@ -23,8 +23,7 @@ namespace Upsilon.Binder.VariableSymbols
|
|||
FunctionOption = options;
|
||||
}
|
||||
|
||||
public override (bool IsValid, string Error,
|
||||
BoundExpression WrongParameter) ValidateParameters(ImmutableArray<BoundExpression> callingParameters)
|
||||
public override bool ValidateParameters(ImmutableArray<BoundExpression> callingParameters)
|
||||
{
|
||||
foreach (var functionVariableSymbolOption in FunctionOption)
|
||||
{
|
||||
|
@ -67,12 +66,10 @@ namespace Upsilon.Binder.VariableSymbols
|
|||
}
|
||||
if (!isValid)
|
||||
continue;
|
||||
return (true, null, null);
|
||||
return true;
|
||||
}
|
||||
|
||||
return (false,
|
||||
$"No valid function with name '{Name}' and variables of type {string.Join(", ", callingParameters.Select(x => $"'{x.Type}'"))} found",
|
||||
null);
|
||||
return false;
|
||||
}
|
||||
|
||||
public TypeContainer GetResultType(BoundExpression[] parameters)
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
using System.Collections.Immutable;
|
||||
using System.Linq;
|
||||
using Upsilon.BaseTypes;
|
||||
using Upsilon.BoundTypes;
|
||||
|
||||
namespace Upsilon.Binder.VariableSymbols
|
||||
{
|
||||
|
@ -12,7 +13,7 @@ namespace Upsilon.Binder.VariableSymbols
|
|||
FunctionOption.Add(new ScriptFunctionVariableOption(resultType, parameters));
|
||||
}
|
||||
|
||||
public override (bool IsValid, string Error, BoundExpression WrongParameter) ValidateParameters(ImmutableArray<BoundExpression> callingParameters)
|
||||
public override bool ValidateParameters(ImmutableArray<BoundExpression> callingParameters)
|
||||
{
|
||||
foreach (var functionVariableSymbolOption in FunctionOption)
|
||||
{
|
||||
|
@ -25,23 +26,37 @@ namespace Upsilon.Binder.VariableSymbols
|
|||
{
|
||||
var functionParameter = option.Parameters[i];
|
||||
var callingParameter = callingParameters[i];
|
||||
if (functionParameter.TypeContainer != BaseTypes.Type.Unknown &&
|
||||
callingParameter.Type != BaseTypes.Type.Unknown &&
|
||||
callingParameter.Type != BaseTypes.Type.Nil)
|
||||
if (functionParameter.TypeContainer == Type.Unknown ||
|
||||
callingParameter.Type == Type.Unknown ||
|
||||
callingParameter.Type == Type.Nil)
|
||||
continue;
|
||||
|
||||
if (!functionParameter.TypeContainer.Type.HasFlag(callingParameter.Type))
|
||||
{
|
||||
if (callingParameter.Type != functionParameter.TypeContainer)
|
||||
isValid = false;
|
||||
break;
|
||||
}
|
||||
|
||||
if (functionParameter.TypeContainer.Type.HasFlag(Type.UserData))
|
||||
{
|
||||
var variable = Binder.ResolveVariable(callingParameter, null);
|
||||
if (variable != null && variable.TypeContainer == Type.UserData)
|
||||
{
|
||||
isValid = false;
|
||||
break;
|
||||
if (!string.Equals(functionParameter.TypeContainer.UserData,
|
||||
callingParameter.Type.UserData))
|
||||
{
|
||||
isValid = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!isValid)
|
||||
continue;
|
||||
return (true, null, null);
|
||||
return true;
|
||||
}
|
||||
|
||||
return (false, null, null);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue