Fixed static scope loader not deriving types properly

This commit is contained in:
Deukhoofd 2018-12-06 16:06:42 +01:00
parent 81cd22ce28
commit 4054f1d383
No known key found for this signature in database
GPG Key ID: B4C087AC81641654
1 changed files with 12 additions and 8 deletions

View File

@ -1,4 +1,5 @@
using System; using System;
using System.Collections;
using System.Collections.Generic; using System.Collections.Generic;
using System.Collections.Immutable; using System.Collections.Immutable;
using System.Linq; using System.Linq;
@ -110,7 +111,7 @@ namespace Upsilon.StandardLibraries
var parameters = new List<InternalFunctionVariableSymbol.InternalFunctionParameter>(); var parameters = new List<InternalFunctionVariableSymbol.InternalFunctionParameter>();
for (var i = 0; i < genericParameters.Length - 1; i++) 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)); parameters.Add(new InternalFunctionVariableSymbol.InternalFunctionParameter(t, false));
} }
@ -121,13 +122,9 @@ namespace Upsilon.StandardLibraries
private static VariableSymbol BuildActionVariableSymbol(string name, System.Type type) private static VariableSymbol BuildActionVariableSymbol(string name, System.Type type)
{ {
var genericParameters = type.GetGenericArguments(); var genericParameters = type.GetGenericArguments();
var parameters = new List<InternalFunctionVariableSymbol.InternalFunctionParameter>(); return new InternalFunctionVariableSymbol(name, true, Type.Nil,
for (var i = 0; i < genericParameters.Length; i++) genericParameters.Select(DeriveValidTypes).Select(t =>
{ new InternalFunctionVariableSymbol.InternalFunctionParameter(t, false)).ToArray());
var t = genericParameters[i].GetScriptType();
parameters.Add(new InternalFunctionVariableSymbol.InternalFunctionParameter(t, false));
}
return new InternalFunctionVariableSymbol(name, true, Type.Nil, parameters.ToArray());
} }
private static Type DeriveValidTypes(System.Type type) private static Type DeriveValidTypes(System.Type type)
@ -145,8 +142,15 @@ namespace Upsilon.StandardLibraries
if (type == typeof(ScriptType)) if (type == typeof(ScriptType))
// allows every type // allows every type
return (Type) 255; return (Type) 255;
if (type == typeof(object))
// allows every type
return (Type) 255;
if (type.IsEnum) if (type.IsEnum)
return Type.Number; return Type.Number;
if (type == typeof(string))
return Type.String;
if (typeof(IEnumerable).IsAssignableFrom(type))
return Type.Table | Type.UserData;
return Type.UserData; return Type.UserData;
} }
} }