diff --git a/Upsilon/Binder/Binder.cs b/Upsilon/Binder/Binder.cs index b2a24b7..45d231c 100644 --- a/Upsilon/Binder/Binder.cs +++ b/Upsilon/Binder/Binder.cs @@ -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) diff --git a/Upsilon/Binder/BoundExpressions/BoundTableExpression.cs b/Upsilon/Binder/BoundExpressions/BoundTableExpression.cs index 584a2f7..9776f02 100644 --- a/Upsilon/Binder/BoundExpressions/BoundTableExpression.cs +++ b/Upsilon/Binder/BoundExpressions/BoundTableExpression.cs @@ -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()