From 613e9dcb09914acd0e677a9c0897c54aa09e82ce Mon Sep 17 00:00:00 2001 From: Deukhoofd Date: Tue, 22 Jan 2019 13:39:57 +0100 Subject: [PATCH] Fix parameters complaining they're not valid when they are valid --- Upsilon/BaseTypes/TypeContainer.cs | 17 ++++++++++++++++- .../BoundTypes/UserDataBoundTypeDefinition.cs | 11 +++++++---- Upsilon/StandardLibraries/StaticScope.cs | 16 ++++++++++------ 3 files changed, 33 insertions(+), 11 deletions(-) diff --git a/Upsilon/BaseTypes/TypeContainer.cs b/Upsilon/BaseTypes/TypeContainer.cs index b458992..e0f69c3 100644 --- a/Upsilon/BaseTypes/TypeContainer.cs +++ b/Upsilon/BaseTypes/TypeContainer.cs @@ -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 diff --git a/Upsilon/BoundTypes/UserDataBoundTypeDefinition.cs b/Upsilon/BoundTypes/UserDataBoundTypeDefinition.cs index e7802e8..f445a43 100644 --- a/Upsilon/BoundTypes/UserDataBoundTypeDefinition.cs +++ b/Upsilon/BoundTypes/UserDataBoundTypeDefinition.cs @@ -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; } diff --git a/Upsilon/StandardLibraries/StaticScope.cs b/Upsilon/StandardLibraries/StaticScope.cs index 7b825aa..d38f7c2 100644 --- a/Upsilon/StandardLibraries/StaticScope.cs +++ b/Upsilon/StandardLibraries/StaticScope.cs @@ -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; } } } \ No newline at end of file