From 575889bed1091922e5ae69f63e2590f4343736e9 Mon Sep 17 00:00:00 2001 From: Deukhoofd Date: Fri, 25 Jan 2019 16:03:00 +0100 Subject: [PATCH] Fix issue where unknown types would bind to the first available type, as they inherit from system.object --- Upsilon/BaseTypes/TypeContainer.cs | 4 ++-- Upsilon/BoundTypes/BoundTypeHandler.cs | 2 ++ Upsilon/BoundTypes/UserDataBoundTypeDefinition.cs | 3 +++ 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/Upsilon/BaseTypes/TypeContainer.cs b/Upsilon/BaseTypes/TypeContainer.cs index c502692..9d702fa 100644 --- a/Upsilon/BaseTypes/TypeContainer.cs +++ b/Upsilon/BaseTypes/TypeContainer.cs @@ -92,14 +92,14 @@ namespace Upsilon.BaseTypes { private System.Type RealType { get; set; } - public UndefinedUserDataTypeContainer(System.Type realType) : base("unset") + public UndefinedUserDataTypeContainer(System.Type realType) : base(realType.Name) { if (realType == null) throw new Exception("Type can't be null"); RealType = realType; } - public UndefinedUserDataTypeContainer(Type t, System.Type realType) : base(t, "unset") + public UndefinedUserDataTypeContainer(Type t, System.Type realType) : base(t, realType.Name) { if (realType == null) throw new Exception("Type can't be null"); diff --git a/Upsilon/BoundTypes/BoundTypeHandler.cs b/Upsilon/BoundTypes/BoundTypeHandler.cs index 4b15aa1..c2408e1 100644 --- a/Upsilon/BoundTypes/BoundTypeHandler.cs +++ b/Upsilon/BoundTypes/BoundTypeHandler.cs @@ -53,6 +53,8 @@ namespace Upsilon.BoundTypes public static string GetTypeName(System.Type type) { + if (type == null) + return null; if (TypeLookup.TryGetValue(type, out var bDefKey)) { return bDefKey; diff --git a/Upsilon/BoundTypes/UserDataBoundTypeDefinition.cs b/Upsilon/BoundTypes/UserDataBoundTypeDefinition.cs index 4d9d5e1..253da1d 100644 --- a/Upsilon/BoundTypes/UserDataBoundTypeDefinition.cs +++ b/Upsilon/BoundTypes/UserDataBoundTypeDefinition.cs @@ -41,6 +41,9 @@ namespace Upsilon.BoundTypes var currentBaseType = type.BaseType; while (currentBaseType != null) { + // We don't want the global object type to be returned + if (currentBaseType == typeof(object)) + break; yield return currentBaseType; currentBaseType = currentBaseType.BaseType; }