Fix parameters complaining they're not valid when they are valid

This commit is contained in:
Deukhoofd 2019-01-22 13:39:57 +01:00
parent 284ba2cf54
commit 613e9dcb09
No known key found for this signature in database
GPG Key ID: B4C087AC81641654
3 changed files with 33 additions and 11 deletions

View File

@ -25,7 +25,17 @@ namespace Upsilon.BaseTypes
{
throw new Exception("Userdata name was null or empty. Not setting this properly will lead to issues later on.");
}
Type = Type.UserData;
Type = Type.UserData;
UserData = userData;
}
public TypeContainer(Type type, string userData)
{
if (string.IsNullOrEmpty(userData))
{
throw new Exception("Userdata name was null or empty. Not setting this properly will lead to issues later on.");
}
Type = type;
UserData = userData;
}
@ -102,6 +112,11 @@ namespace Upsilon.BaseTypes
RealType = realType;
}
public UndefinedUserDataTypeContainer(Type t, System.Type realType) : base(t, "unset")
{
RealType = realType;
}
private string _userData;
public override string UserData

View File

@ -219,12 +219,15 @@ namespace Upsilon.BoundTypes
(UserDataBoundTypeDefinition) ((UserDataVariableSymbol) variable).BoundTypeDefinition;
if (parent.ValidInternalTypes.Length != 0)
{
if (functionParameter.ActualType != null &&
!parent.ValidInternalTypes.Any(x => string.Equals(x.Name, functionParameter.ActualType)))
if (functionParameter.ActualType != null)
{
return false;
if (!parent.ValidInternalTypes.Any(x =>
string.Equals(x.Name, functionParameter.ActualType)))
{
return false;
}
}
if (!string.Equals(parent.Name, functionParameter.ActualType, StringComparison.InvariantCultureIgnoreCase))
else if (!string.Equals(parent.Name, functionParameter.ActualType, StringComparison.InvariantCultureIgnoreCase))
{
return false;
}

View File

@ -147,7 +147,12 @@ namespace Upsilon.StandardLibraries
public static TypeContainer DeriveValidTypes(System.Type type)
{
if (type.IsEnum)
return Type.UserData | Type.Number;
{
var boundEnumType = BoundTypeHandler.GetTypeName(type);
if (boundEnumType != null)
return new TypeContainer(Type.UserData | Type.Number, boundEnumType);
return new UndefinedUserDataTypeContainer(Type.UserData | Type.Number, type);
}
var typeCode = System.Type.GetTypeCode(type);
switch (typeCode)
@ -169,9 +174,6 @@ namespace Upsilon.StandardLibraries
case TypeCode.Char:
case TypeCode.String:
return Type.String;
case TypeCode.Object:
// allows every type
return (Type) 255;
}
if (type == typeof(ScriptString))
return Type.String;
@ -192,8 +194,10 @@ namespace Upsilon.StandardLibraries
if (type == typeof(ScriptType))
// allows every type
return (Type) 255;
return Type.UserData;
var boundType = BoundTypeHandler.GetTypeName(type);
if (boundType != null)
return new TypeContainer(boundType);
return Type.Unknown;
}
}
}