Fixes for types sometimes choosing type they inherit from instead of themselves
This commit is contained in:
parent
8bd5f7d0af
commit
4062d2f140
|
@ -1,5 +1,6 @@
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Immutable;
|
using System.Collections.Immutable;
|
||||||
|
using System.Diagnostics;
|
||||||
using Upsilon.BoundTypes;
|
using Upsilon.BoundTypes;
|
||||||
|
|
||||||
namespace Upsilon.BaseTypes
|
namespace Upsilon.BaseTypes
|
||||||
|
@ -103,17 +104,17 @@ namespace Upsilon.BaseTypes
|
||||||
{
|
{
|
||||||
private System.Type RealType { get; set; }
|
private System.Type RealType { get; set; }
|
||||||
|
|
||||||
protected UndefinedUserDataTypeContainer(Type t) : base(t)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
public UndefinedUserDataTypeContainer(System.Type realType) : base("unset")
|
public UndefinedUserDataTypeContainer(System.Type realType) : base("unset")
|
||||||
{
|
{
|
||||||
|
if (realType == null)
|
||||||
|
throw new Exception("Type can't be null");
|
||||||
RealType = realType;
|
RealType = realType;
|
||||||
}
|
}
|
||||||
|
|
||||||
public UndefinedUserDataTypeContainer(Type t, System.Type realType) : base(t, "unset")
|
public UndefinedUserDataTypeContainer(Type t, System.Type realType) : base(t, "unset")
|
||||||
{
|
{
|
||||||
|
if (realType == null)
|
||||||
|
throw new Exception("Type can't be null");
|
||||||
RealType = realType;
|
RealType = realType;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -174,10 +174,7 @@ namespace Upsilon.BaseTypes
|
||||||
|
|
||||||
if (t == typeof(ScriptType))
|
if (t == typeof(ScriptType))
|
||||||
return Type.Unknown;
|
return Type.Unknown;
|
||||||
var boundType = BoundTypeHandler.GetTypeName(t);
|
|
||||||
if (boundType == null)
|
|
||||||
return new UndefinedUserDataTypeContainer(t);
|
return new UndefinedUserDataTypeContainer(t);
|
||||||
return new TypeContainer(BoundTypeHandler.GetTypeName(t));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,8 +16,6 @@ namespace Upsilon.BaseTypes.UserData
|
||||||
|
|
||||||
public static void LoadType(System.Type t, string name)
|
public static void LoadType(System.Type t, string name)
|
||||||
{
|
{
|
||||||
var info = new UserDataType(t);
|
|
||||||
Types.AddOrUpdate(t, info, (type, dataType) => dataType);
|
|
||||||
UserDataBoundTypeDefinition boundType;
|
UserDataBoundTypeDefinition boundType;
|
||||||
if (t.IsEnum)
|
if (t.IsEnum)
|
||||||
{
|
{
|
||||||
|
@ -28,6 +26,8 @@ namespace Upsilon.BaseTypes.UserData
|
||||||
boundType = UserDataBoundTypeDefinition.Create(t, name);
|
boundType = UserDataBoundTypeDefinition.Create(t, name);
|
||||||
}
|
}
|
||||||
BoundTypeHandler.LoadUserDataTypeDefinition(boundType);
|
BoundTypeHandler.LoadUserDataTypeDefinition(boundType);
|
||||||
|
var info = new UserDataType(t);
|
||||||
|
Types.AddOrUpdate(t, info, (type, dataType) => dataType);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void LoadAssembly(Assembly assembly)
|
public static void LoadAssembly(Assembly assembly)
|
||||||
|
|
|
@ -378,6 +378,12 @@ namespace Upsilon.Binder
|
||||||
diagnostics?.LogWarning($"Can't resolve type '{bDefProperty.ToString()}'", fullStopIndexExpression.Span);
|
diagnostics?.LogWarning($"Can't resolve type '{bDefProperty.ToString()}'", fullStopIndexExpression.Span);
|
||||||
return new VariableSymbol(fullStopIndexExpression.Index, Type.Unknown, true);
|
return new VariableSymbol(fullStopIndexExpression.Index, Type.Unknown, true);
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
diagnostics?.LogWarning(
|
||||||
|
$"Can't resolve property '{fullStopIndexExpression.Index}' on type {parent.Name}",
|
||||||
|
fullStopIndexExpression.Span);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else if (indexerVariable.TypeContainer == Type.Unknown)
|
else if (indexerVariable.TypeContainer == Type.Unknown)
|
||||||
{
|
{
|
||||||
|
@ -492,9 +498,17 @@ namespace Upsilon.Binder
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (assignment.Type == Type.UserData)
|
else if (assignment.Type == Type.UserData)
|
||||||
|
{
|
||||||
|
var ud = assignment.Type.UserData;
|
||||||
|
if (ud == null)
|
||||||
|
{
|
||||||
|
variable = new VariableSymbol(name, Type.Unknown, isLocal);
|
||||||
|
}
|
||||||
|
else
|
||||||
{
|
{
|
||||||
variable = new UserDataVariableSymbol(name,
|
variable = new UserDataVariableSymbol(name,
|
||||||
BoundTypeHandler.GetTypeDefinition(assignment.Type.UserData), isLocal);
|
BoundTypeHandler.GetTypeDefinition(ud), isLocal);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
using System.Collections;
|
using System.Collections;
|
||||||
using System.Collections.Concurrent;
|
using System.Collections.Concurrent;
|
||||||
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using Upsilon.BaseTypes;
|
using Upsilon.BaseTypes;
|
||||||
|
|
||||||
|
@ -17,12 +18,21 @@ namespace Upsilon.BoundTypes
|
||||||
dic.TryAdd("function", new BoundTypeDefinition(Type.Function, new System.Type[0]));
|
dic.TryAdd("function", new BoundTypeDefinition(Type.Function, new System.Type[0]));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static readonly ConcurrentDictionary<System.Type, string> TypeLookup =
|
||||||
|
new ConcurrentDictionary<System.Type, string>();
|
||||||
private static readonly ConcurrentDictionary<string, BoundTypeDefinition> TypeDefinitions = Reset();
|
private static readonly ConcurrentDictionary<string, BoundTypeDefinition> TypeDefinitions = Reset();
|
||||||
|
|
||||||
public static ConcurrentDictionary<string, BoundTypeDefinition> Reset()
|
public static ConcurrentDictionary<string, BoundTypeDefinition> Reset()
|
||||||
{
|
{
|
||||||
var dic = new ConcurrentDictionary<string, BoundTypeDefinition>();
|
var dic = new ConcurrentDictionary<string, BoundTypeDefinition>();
|
||||||
AddDefaults(dic);
|
AddDefaults(dic);
|
||||||
|
foreach (var boundTypeDefinition in dic)
|
||||||
|
{
|
||||||
|
foreach (var valueValidInternalType in boundTypeDefinition.Value.ValidInternalTypes)
|
||||||
|
{
|
||||||
|
TypeLookup.TryAdd(valueValidInternalType, boundTypeDefinition.Key);
|
||||||
|
}
|
||||||
|
}
|
||||||
return dic;
|
return dic;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -43,14 +53,28 @@ namespace Upsilon.BoundTypes
|
||||||
|
|
||||||
public static string GetTypeName(System.Type type)
|
public static string GetTypeName(System.Type type)
|
||||||
{
|
{
|
||||||
return TypeDefinitions.FirstOrDefault(x =>
|
if (TypeLookup.TryGetValue(type, out var bDefKey))
|
||||||
x.Value.ValidInternalTypes.Any(validType => validType.IsAssignableFrom(type))).Key;
|
{
|
||||||
|
return bDefKey;
|
||||||
|
}
|
||||||
|
|
||||||
|
var bDef = TypeDefinitions.FirstOrDefault(x =>
|
||||||
|
x.Value.ValidInternalTypes.Any(validType => validType.IsAssignableFrom(type)));
|
||||||
|
if (!bDef.Equals(default(KeyValuePair<string, BoundTypeDefinition>)))
|
||||||
|
{
|
||||||
|
TypeLookup.TryAdd(type, bDef.Key);
|
||||||
|
}
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void LoadUserDataTypeDefinition(UserDataBoundTypeDefinition def)
|
public static void LoadUserDataTypeDefinition(UserDataBoundTypeDefinition def)
|
||||||
{
|
{
|
||||||
var key = def.Name.ToLowerInvariant();
|
var key = def.Name.ToLowerInvariant();
|
||||||
TypeDefinitions.AddOrUpdate(key, def, (s, definition) => definition);
|
TypeDefinitions.AddOrUpdate(key, def, (s, definition) => definition);
|
||||||
|
foreach (var valueValidInternalType in def.ValidInternalTypes)
|
||||||
|
{
|
||||||
|
TypeLookup.TryAdd(valueValidInternalType, key);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -196,10 +196,7 @@ namespace Upsilon.StandardLibraries
|
||||||
if (type == typeof(ScriptType))
|
if (type == typeof(ScriptType))
|
||||||
// allows every type
|
// allows every type
|
||||||
return (Type) 255;
|
return (Type) 255;
|
||||||
var boundType = BoundTypeHandler.GetTypeName(type);
|
return new UndefinedUserDataTypeContainer(Type.UserData, type);
|
||||||
if (boundType != null)
|
|
||||||
return new TypeContainer(boundType);
|
|
||||||
return Type.Unknown;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue