Better handling of getting valid bound type.
This commit is contained in:
parent
18ca112624
commit
685cae2dc6
|
@ -1,6 +1,5 @@
|
||||||
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
|
||||||
|
|
|
@ -61,7 +61,12 @@ namespace Upsilon.BoundTypes
|
||||||
}
|
}
|
||||||
|
|
||||||
var bDef = TypeDefinitions.FirstOrDefault(x =>
|
var bDef = TypeDefinitions.FirstOrDefault(x =>
|
||||||
x.Value.ValidInternalTypes.Any(validType => validType.IsAssignableFrom(type)));
|
{
|
||||||
|
var first = x.Value.ValidInternalTypes.FirstOrDefault();
|
||||||
|
if (first == null)
|
||||||
|
return false;
|
||||||
|
return first.IsAssignableFrom(type);
|
||||||
|
});
|
||||||
if (!bDef.Equals(default(KeyValuePair<string, BoundTypeDefinition>)))
|
if (!bDef.Equals(default(KeyValuePair<string, BoundTypeDefinition>)))
|
||||||
{
|
{
|
||||||
TypeLookup.TryAdd(type, bDef.Key);
|
TypeLookup.TryAdd(type, bDef.Key);
|
||||||
|
|
|
@ -44,6 +44,8 @@ namespace Upsilon.BoundTypes
|
||||||
// We don't want the global object type to be returned
|
// We don't want the global object type to be returned
|
||||||
if (currentBaseType == typeof(object))
|
if (currentBaseType == typeof(object))
|
||||||
break;
|
break;
|
||||||
|
if (currentBaseType == typeof(ValueType))
|
||||||
|
break;
|
||||||
yield return currentBaseType;
|
yield return currentBaseType;
|
||||||
currentBaseType = currentBaseType.BaseType;
|
currentBaseType = currentBaseType.BaseType;
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,8 +14,8 @@ namespace UpsilonTests.GeneralTests
|
||||||
public void BasicStringVariable()
|
public void BasicStringVariable()
|
||||||
{
|
{
|
||||||
const string input = @"
|
const string input = @"
|
||||||
string = ""test""
|
str = ""test""
|
||||||
return string
|
return str
|
||||||
";
|
";
|
||||||
var evaluated = Executor.EvaluateScript<string>(input, Options);
|
var evaluated = Executor.EvaluateScript<string>(input, Options);
|
||||||
Assert.Equal("test", evaluated);
|
Assert.Equal("test", evaluated);
|
||||||
|
@ -25,8 +25,8 @@ return string
|
||||||
public void StringIndexable()
|
public void StringIndexable()
|
||||||
{
|
{
|
||||||
const string input = @"
|
const string input = @"
|
||||||
string = ""test""
|
str = ""test""
|
||||||
return string[3]
|
return str[3]
|
||||||
";
|
";
|
||||||
var evaluated = Executor.EvaluateScript<string>(input, Options);
|
var evaluated = Executor.EvaluateScript<string>(input, Options);
|
||||||
Assert.Equal("s", evaluated);
|
Assert.Equal("s", evaluated);
|
||||||
|
@ -36,8 +36,8 @@ return string[3]
|
||||||
public void StringAddition()
|
public void StringAddition()
|
||||||
{
|
{
|
||||||
const string input = @"
|
const string input = @"
|
||||||
string = ""test"" + ""123""
|
str = ""test"" + ""123""
|
||||||
return string
|
return str
|
||||||
";
|
";
|
||||||
var evaluated = Executor.EvaluateScript<string>(input, Options);
|
var evaluated = Executor.EvaluateScript<string>(input, Options);
|
||||||
Assert.Equal("test123", evaluated);
|
Assert.Equal("test123", evaluated);
|
||||||
|
|
Loading…
Reference in New Issue