Fix function calls in fullstop index expressions not binding properly

This commit is contained in:
Deukhoofd 2019-01-21 18:45:02 +01:00
parent a9f6b682dc
commit e5f08d5859
No known key found for this signature in database
GPG Key ID: B4C087AC81641654
2 changed files with 43 additions and 38 deletions

View File

@ -230,45 +230,45 @@ namespace Upsilon.Binder
{
if (function is ScriptFunctionVariableSymbol scriptFunction)
{
if (!(scriptFunction.GetFirstValid(parameters.Select(x => x.Type).ToArray()) is ScriptFunctionVariableOption functionOption))
throw new Exception();
if (!functionOption.IsBound)
if ((scriptFunction.GetFirstValid(parameters.Select(x => x.Type).ToArray()) is ScriptFunctionVariableOption functionOption))
{
Scope = new BoundScope(Scope);
for (var index = 0; index < functionOption.Parameters.Length; index++)
if (!functionOption.IsBound)
{
var functionVariable = functionOption.Parameters[index];
var callingVariable = parameters[index];
functionVariable.TypeContainer = callingVariable.Type;
Scope.DefineLocalVariable(functionVariable);
}
UnboundFunctionExpression unbound = null;
foreach (var functionExpression in _unboundFunctions.Where(x =>
{
if (x.Name == function.Name)
Scope = new BoundScope(Scope);
for (var index = 0; index < functionOption.Parameters.Length; index++)
{
return parameters.Count == functionOption.Parameters.Length;
var functionVariable = functionOption.Parameters[index];
var callingVariable = parameters[index];
functionVariable.TypeContainer = callingVariable.Type;
Scope.DefineLocalVariable(functionVariable);
}
UnboundFunctionExpression unbound = null;
foreach (var functionExpression in _unboundFunctions.Where(x =>
{
if (x.Name == function.Name)
{
return parameters.Count == functionOption.Parameters.Length;
}
return false;
}))
{
unbound = functionExpression;
break;
}
if (unbound != null)
{
unbound.Block = (BoundBlockStatement) BindBlockStatement(unbound.UnboundBlock);
returnType = Scope.ReturnType;
Scope = Scope.ParentScope;
functionOption.IsBound = true;
functionOption.ResultType = returnType;
}
return false;
}))
{
unbound = functionExpression;
break;
}
if (unbound != null)
{
unbound.Block = (BoundBlockStatement) BindBlockStatement(unbound.UnboundBlock);
returnType = Scope.ReturnType;
Scope = Scope.ParentScope;
functionOption.IsBound = true;
functionOption.ResultType = returnType;
}
}
}
else
@ -432,6 +432,11 @@ namespace Upsilon.Binder
}
else if (expression.Kind == BoundKind.BoundFunctionCallExpression)
{
if (expression.Type == Type.UserData)
{
var boundDef = BoundTypeHandler.GetTypeDefinition(expression.Type.UserData);
return new UserDataVariableSymbol("", boundDef, true);
}
return new VariableSymbol("", expression.Type, true);
}
else if (expression.Type == Type.Unknown)

View File

@ -28,7 +28,7 @@ namespace Upsilon.Binder
{
get
{
Type? valueType = null;
TypeContainer valueType = null;
foreach (var statement in Statements)
{
if (!(statement is BoundExpressionStatement exp))
@ -36,7 +36,7 @@ namespace Upsilon.Binder
valueType = BaseTypes.Type.Unknown;
break;
}
if (!valueType.HasValue)
if (valueType == null)
{
valueType = exp.Expression.Type;
continue;
@ -46,9 +46,9 @@ namespace Upsilon.Binder
break;
}
var valueRealType = BaseTypes.Type.Unknown;
if (valueType.HasValue)
valueRealType = valueType.Value;
TypeContainer valueRealType = BaseTypes.Type.Unknown;
if (valueType != null)
valueRealType = valueType;
var arr = new TypeContainer[] {BaseTypes.Type.String, valueRealType};
return new CompositeTypeContainer()