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 (function is ScriptFunctionVariableSymbol scriptFunction)
{ {
if (!(scriptFunction.GetFirstValid(parameters.Select(x => x.Type).ToArray()) is ScriptFunctionVariableOption functionOption)) if ((scriptFunction.GetFirstValid(parameters.Select(x => x.Type).ToArray()) is ScriptFunctionVariableOption functionOption))
throw new Exception();
if (!functionOption.IsBound)
{ {
Scope = new BoundScope(Scope); if (!functionOption.IsBound)
for (var index = 0; index < functionOption.Parameters.Length; index++)
{ {
var functionVariable = functionOption.Parameters[index]; Scope = new BoundScope(Scope);
var callingVariable = parameters[index]; for (var index = 0; index < functionOption.Parameters.Length; 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; 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 else
@ -432,6 +432,11 @@ namespace Upsilon.Binder
} }
else if (expression.Kind == BoundKind.BoundFunctionCallExpression) 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); return new VariableSymbol("", expression.Type, true);
} }
else if (expression.Type == Type.Unknown) else if (expression.Type == Type.Unknown)

View File

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