Skip to content

Commit 5a15c51

Browse files
committed
fixed: #473
1 parent 8ff4b74 commit 5a15c51

File tree

2 files changed

+8
-6
lines changed

2 files changed

+8
-6
lines changed

src/FastExpressionCompiler/FastExpressionCompiler.cs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6007,7 +6007,8 @@ private static bool TryEmitConditional(
60076007
{
60086008
oppositeTestExpr = sideDefaultExpr == testLeftExpr ? testRightExpr : testLeftExpr;
60096009
var testSideType = sideDefaultExpr.Type;
6010-
if (testSideType.IsPrimitiveOrDecimalWithZeroDefault())
6010+
// except decimal, because its 0 is Decimal.Zero a struct and is not working with Brtrue/Brfalse
6011+
if (testSideType.IsPrimitiveWithZeroDefaultExceptDecimal())
60116012
useBrFalseOrTrue = 0;
60126013
else if (testSideType.IsClass || testSideType.IsNullable())
60136014
{
@@ -8523,7 +8524,7 @@ internal static bool IsFloatingPoint(this Type type) =>
85238524
type == typeof(float) ||
85248525
type == typeof(double);
85258526

8526-
internal static bool IsPrimitiveOrDecimalWithZeroDefault(this Type type)
8527+
internal static bool IsPrimitiveWithZeroDefaultExceptDecimal(this Type type)
85278528
{
85288529
switch (Type.GetTypeCode(type))
85298530
{
@@ -8539,10 +8540,7 @@ internal static bool IsPrimitiveOrDecimalWithZeroDefault(this Type type)
85398540
case TypeCode.UInt64:
85408541
case TypeCode.Single:
85418542
case TypeCode.Double:
8542-
case TypeCode.Decimal:
85438543
return true;
8544-
// case TypeCode.DateTime:
8545-
// case TypeCode.String:
85468544
default:
85478545
return false;
85488546
}

test/FastExpressionCompiler.IssueTests/Issue473_InvalidProgramException_when_using_Expression_Condition_with_converted_decimal_expression.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,12 @@ public void Original_case(TestContext t)
3434
fs.PrintIL();
3535
t.AreEqual(3, fs());
3636

37-
var ff = expr.CompileFast(false);
37+
var ff = expr.CompileFast(false, CompilerFlags.DisableInterpreter);
3838
ff.PrintIL();
3939
t.AreEqual(3, ff());
40+
41+
var ffi = expr.CompileFast(false);
42+
ff.PrintIL();
43+
t.AreEqual(3, ffi());
4044
}
4145
}

0 commit comments

Comments
 (0)