diff --git a/src/FastExpressionCompiler.LightExpression/Expression.cs b/src/FastExpressionCompiler.LightExpression/Expression.cs index cffa9ff9..977ff9f1 100644 --- a/src/FastExpressionCompiler.LightExpression/Expression.cs +++ b/src/FastExpressionCompiler.LightExpression/Expression.cs @@ -5380,13 +5380,13 @@ internal LoopExpression(Expression body, LabelTarget breakLabel, LabelTarget con protected internal override Expression Accept(ExpressionVisitor visitor) => visitor.VisitLoop(this); #endif internal override SysExpr CreateSysExpression(ref SmallList exprsConverted) => + ContinueLabel != null + ? SysExpr.Loop(Body.ToExpression(ref exprsConverted), + BreakLabel?.ToSystemLabelTarget(ref exprsConverted), + ContinueLabel.ToSystemLabelTarget(ref exprsConverted)) : BreakLabel == null - ? SysExpr.Loop(Body.ToExpression(ref exprsConverted)) : - ContinueLabel == null - ? SysExpr.Loop(Body.ToExpression(ref exprsConverted), BreakLabel.ToSystemLabelTarget(ref exprsConverted)) : - SysExpr.Loop(Body.ToExpression(ref exprsConverted), - BreakLabel.ToSystemLabelTarget(ref exprsConverted), - ContinueLabel.ToSystemLabelTarget(ref exprsConverted)); + ? SysExpr.Loop(Body.ToExpression(ref exprsConverted)) + : SysExpr.Loop(Body.ToExpression(ref exprsConverted), BreakLabel.ToSystemLabelTarget(ref exprsConverted)); } public class TryExpression : Expression diff --git a/test/FastExpressionCompiler.LightExpression.UnitTests/LightExpressionTests.cs b/test/FastExpressionCompiler.LightExpression.UnitTests/LightExpressionTests.cs index 70658440..e7dd836d 100644 --- a/test/FastExpressionCompiler.LightExpression.UnitTests/LightExpressionTests.cs +++ b/test/FastExpressionCompiler.LightExpression.UnitTests/LightExpressionTests.cs @@ -28,6 +28,7 @@ public int Run() Can_embed_normal_Expression_into_LightExpression_eg_as_Constructor_argument(); Should_output_the_System_and_LightExpression_to_the_identical_construction_syntax(); Should_output_the_System_and_LightExpression_to_the_identical_CSharp_syntax(); + Light_loop_with_continue_label_and_no_break_label_keeps_the_continue_label_in_the_system_expression(); Expression_produced_by_ToExpressionString_should_compile(); Multiple_methods_in_block_should_be_aligned_when_output_to_csharp(); Can_roundtrip_light_expression_through_flat_expression(); @@ -2549,6 +2550,15 @@ public void Should_output_the_System_and_LightExpression_to_the_identical_constr } + public void Light_loop_with_continue_label_and_no_break_label_keeps_the_continue_label_in_the_system_expression() + { + var cont = Label("cont"); + var le = Lambda(Loop(Block(Continue(cont)), null, cont)); + var loop = (System.Linq.Expressions.LoopExpression)le.ToLambdaExpression().Body; + Asserts.AreEqual(null, loop.BreakLabel); + Asserts.AreEqual("cont", loop.ContinueLabel?.Name); + } + public void Should_output_the_System_and_LightExpression_to_the_identical_CSharp_syntax() { var se = CreateComplexExpression("p");