Skip to content

Commit 57a62dd

Browse files
committed
added missing Expression.MakeCatchBlock; changed CatchBlock to the class; added the failing test for #222
1 parent ae80ce0 commit 57a62dd

File tree

4 files changed

+559
-10
lines changed

4 files changed

+559
-10
lines changed

src/FastExpressionCompiler.LightExpression/Expression.cs

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1308,10 +1308,13 @@ public static TryExpression TryFinally(Expression body, Expression @finally) =>
13081308
new WithFinallyTryExpression(body, null, @finally);
13091309

13101310
public static CatchBlock Catch(ParameterExpression variable, Expression body) =>
1311-
new CatchBlock(variable, body, null, variable.Type);
1311+
new CatchBlock(variable.Type, variable, body, null);
13121312

13131313
public static CatchBlock Catch(Type test, Expression body) =>
1314-
new CatchBlock(null, body, null, test);
1314+
new CatchBlock(test, null, body, null);
1315+
1316+
public static CatchBlock MakeCatchBlock(Type test, ParameterExpression variable, Expression body, Expression filter) =>
1317+
new CatchBlock(test, variable, body, filter);
13151318

13161319
/// <summary>Creates a UnaryExpression that represents a throwing of an exception.</summary>
13171320
public static UnaryExpression Throw(Expression value) => new ThrowUnaryExpression(value);
@@ -3247,19 +3250,18 @@ internal WithFinallyTryExpression(Expression body, CatchBlock[] handlers, Expres
32473250
Finally = @finally;
32483251
}
32493252

3250-
// todo: @perf convert to class and minimize the memory for the general cases
3251-
public struct CatchBlock
3253+
public sealed class CatchBlock
32523254
{
3255+
public readonly Type Test;
32533256
public readonly ParameterExpression Variable;
32543257
public readonly Expression Body;
32553258
public readonly Expression Filter;
3256-
public readonly Type Test;
3257-
internal CatchBlock(ParameterExpression variable, Expression body, Expression filter, Type test)
3259+
internal CatchBlock(Type test, ParameterExpression variable, Expression body, Expression filter)
32583260
{
3261+
Test = test;
32593262
Variable = variable;
3260-
Body = body;
3261-
Filter = filter;
3262-
Test = test;
3263+
Body = body;
3264+
Filter = filter;
32633265
}
32643266
}
32653267

src/FastExpressionCompiler.LightExpression/ExpressionVisitor.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -405,7 +405,7 @@ protected internal virtual CatchBlock VisitCatchBlock(CatchBlock node)
405405
var body = Visit(node.Body);
406406
if (variable == node.Variable && filter == node.Filter && body == node.Body)
407407
return node;
408-
return new CatchBlock(variable, body, filter, node.Test);
408+
return new CatchBlock(node.Test, variable, body, filter);
409409
}
410410

411411
protected internal virtual Expression VisitTry(TryExpression node)

0 commit comments

Comments
 (0)