Skip to content

Commit cbb3900

Browse files
committed
1 parent ea332ca commit cbb3900

File tree

2 files changed

+24
-27
lines changed

2 files changed

+24
-27
lines changed

src/System.Linq.Dynamic.Core/ExpressionParser.cs

+10-13
Original file line numberDiff line numberDiff line change
@@ -534,12 +534,12 @@ Expression ParseIn()
534534
else if (left.Type != right.Type)
535535
{
536536
//check for nullable type match
537-
if (!left.Type.GetTypeInfo().IsGenericType ||
538-
left.Type.GetGenericTypeDefinition() != typeof(Nullable<>) ||
539-
left.Type.GetTypeInfo().GetGenericTypeArguments()[0] != right.Type)
540-
{
541-
throw ParseError(op.Pos, Res.ExpressionTypeMismatch, left.Type);
542-
}
537+
//if (!left.Type.GetTypeInfo().IsGenericType ||
538+
// left.Type.GetGenericTypeDefinition() != typeof(Nullable<>) ||
539+
// left.Type.GetTypeInfo().GetGenericTypeArguments()[0] != right.Type)
540+
//{
541+
// throw ParseError(op.Pos, Res.ExpressionTypeMismatch, left.Type);
542+
//}
543543

544544
CheckAndPromoteOperands(typeof(IEqualitySignatures), "==", ref left, ref right, op.Pos);
545545
}
@@ -739,17 +739,14 @@ private ConstantExpression ParseEnumToConstantExpression(int pos, Type leftType,
739739

740740
private object ParseConstantExpressionToEnum(int pos, Type leftType, ConstantExpression constantExpr)
741741
{
742-
object parsedEnum = null;
743742
try
744743
{
745744
if (constantExpr.Value is string)
746745
{
747-
return parsedEnum = Enum.Parse(GetNonNullableType(leftType), constantExpr.Value as string, true);
748-
}
749-
else
750-
{
751-
return parsedEnum = Enum.ToObject(leftType, constantExpr.Value);
746+
return Enum.Parse(GetNonNullableType(leftType), (string)constantExpr.Value, true);
752747
}
748+
749+
return Enum.ToObject(leftType, constantExpr.Value);
753750
}
754751
catch
755752
{
@@ -975,7 +972,7 @@ Expression ParseIntegerLiteral()
975972
return CreateLiteral(value, text);
976973
}
977974

978-
if (value <= (int)short.MaxValue) return CreateLiteral((short)value, text);
975+
// if (value <= (int)short.MaxValue) return CreateLiteral((short)value, text);
979976
if (value <= int.MaxValue) return CreateLiteral((int)value, text);
980977
if (value <= uint.MaxValue) return CreateLiteral((uint)value, text);
981978
if (value <= long.MaxValue) return CreateLiteral((long)value, text);

test/System.Linq.Dynamic.Core.Tests/ExpressionTests.cs

+14-14
Original file line numberDiff line numberDiff line change
@@ -801,6 +801,20 @@ public void ExpressionTests_In_Enum()
801801
Check.That(result2).ContainsExactly(expected);
802802
}
803803

804+
[Fact]
805+
public void ExpressionTests_In_Short()
806+
{
807+
// Arrange
808+
var qry = new short[] { 1, 2, 3, 4, 5, 6, 7 }.AsQueryable();
809+
810+
// Act
811+
var result = qry.Where("it in (1,2)");
812+
var resultExpected = qry.Where(x => x == 1 || x == 2);
813+
814+
// Assert
815+
Check.That(resultExpected.ToArray()).ContainsExactly(result.ToDynamicArray<short>());
816+
}
817+
804818
[Fact]
805819
public void ExpressionTests_In_String()
806820
{
@@ -1430,20 +1444,6 @@ public void ExpressionTests_Type_Integer_Qualifiers_Exceptions()
14301444
Assert.Throws<ParseException>(() => values.Where("it < -2B"));
14311445
}
14321446

1433-
[Fact]
1434-
public void ExpressionTests_Type_Short()
1435-
{
1436-
// Arrange
1437-
var qry = new short[] { 1, 2, 3, 4, 5, 6, 7 }.AsQueryable();
1438-
1439-
// Act
1440-
var result = qry.Where("it in (1,2)");
1441-
var resultExpected = qry.Where(x => x == 1 || x == 2);
1442-
1443-
// Assert
1444-
Check.That(resultExpected.ToArray()).ContainsExactly(result.ToDynamicArray<short>());
1445-
}
1446-
14471447
[Fact]
14481448
public void ExpressionTests_Uri()
14491449
{

0 commit comments

Comments
 (0)