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.Collections;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Linq;
@ -110,7 +111,7 @@ namespace Upsilon.StandardLibraries
var parameters = new List<InternalFunctionVariableSymbol.InternalFunctionParameter>();
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<InternalFunctionVariableSymbol.InternalFunctionParameter>();
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;
}
}