From 4054f1d38387d4fea2534b07d5f3a951d73f0298 Mon Sep 17 00:00:00 2001 From: Deukhoofd Date: Thu, 6 Dec 2018 16:06:42 +0100 Subject: [PATCH] Fixed static scope loader not deriving types properly --- Upsilon/StandardLibraries/StaticScope.cs | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/Upsilon/StandardLibraries/StaticScope.cs b/Upsilon/StandardLibraries/StaticScope.cs index e74aa90..24d0f19 100644 --- a/Upsilon/StandardLibraries/StaticScope.cs +++ b/Upsilon/StandardLibraries/StaticScope.cs @@ -1,4 +1,5 @@ using System; +using System.Collections; using System.Collections.Generic; using System.Collections.Immutable; using System.Linq; @@ -110,7 +111,7 @@ namespace Upsilon.StandardLibraries var parameters = new List(); for (var i = 0; i < genericParameters.Length - 1; i++) { - var t = genericParameters[i].GetScriptType(); + var t = DeriveValidTypes(genericParameters[i]); parameters.Add(new InternalFunctionVariableSymbol.InternalFunctionParameter(t, false)); } @@ -121,13 +122,9 @@ namespace Upsilon.StandardLibraries private static VariableSymbol BuildActionVariableSymbol(string name, System.Type type) { var genericParameters = type.GetGenericArguments(); - var parameters = new List(); - for (var i = 0; i < genericParameters.Length; i++) - { - var t = genericParameters[i].GetScriptType(); - parameters.Add(new InternalFunctionVariableSymbol.InternalFunctionParameter(t, false)); - } - return new InternalFunctionVariableSymbol(name, true, Type.Nil, parameters.ToArray()); + return new InternalFunctionVariableSymbol(name, true, Type.Nil, + genericParameters.Select(DeriveValidTypes).Select(t => + new InternalFunctionVariableSymbol.InternalFunctionParameter(t, false)).ToArray()); } private static Type DeriveValidTypes(System.Type type) @@ -145,8 +142,15 @@ namespace Upsilon.StandardLibraries if (type == typeof(ScriptType)) // allows every type return (Type) 255; + if (type == typeof(object)) + // allows every type + return (Type) 255; if (type.IsEnum) return Type.Number; + if (type == typeof(string)) + return Type.String; + if (typeof(IEnumerable).IsAssignableFrom(type)) + return Type.Table | Type.UserData; return Type.UserData; } }