From 4905d6966ca4e54c5a017c28cbe2580f7cb618d8 Mon Sep 17 00:00:00 2001 From: Xinlong Hu Date: Fri, 18 Jul 2025 21:12:43 -0500 Subject: [PATCH] Fixing With statement test cases --- .../templates/Block.py | 21 +++++++++++++++++++ test/With.py | 6 ------ 2 files changed, 21 insertions(+), 6 deletions(-) diff --git a/pylingual/control_flow_reconstruction/templates/Block.py b/pylingual/control_flow_reconstruction/templates/Block.py index 86c7321..2734ec4 100644 --- a/pylingual/control_flow_reconstruction/templates/Block.py +++ b/pylingual/control_flow_reconstruction/templates/Block.py @@ -75,6 +75,27 @@ class JumpTemplate(ControlFlowTemplate): to_indented_source = defer_source_to("body") +@register_template(0, 0) +class JumpTemplate(ControlFlowTemplate): + template = T( + body=~N("jump", None).with_cond(without_instructions("CLEANUP_THROW")), + jump=N("tail", "block?").with_in_deg(1).with_cond(exact_instructions("JUMP_BACKWARD_NO_INTERRUPT"), exact_instructions("POP_JUMP_IF_TRUE")), + block=~N.tail(), + tail=N.tail(), + ) + + try_match = make_try_match( + { + EdgeKind.Fall: "tail", + EdgeKind.TrueJump: "block", + }, + "body", + "jump", + ) + + to_indented_source = defer_source_to("body") + + @register_template(0, 20) @register_template(2, 20) class BlockTemplate(ControlFlowTemplate): diff --git a/test/With.py b/test/With.py index 491f463..d4b4fc0 100644 --- a/test/With.py +++ b/test/With.py @@ -7,7 +7,6 @@ def a1_bare_with_fallthrough(): print(1) print(2) -# Fails in 3.10, duplicate blocks explained further in issue 32 def b0_multi_with(): with a, b: print(1) @@ -26,7 +25,6 @@ def c1_with_as_fallthrough(): print(1) print(2) -# Fails in 3.10, same issue as b def d0_multi_with_as(): with a, b as c: print(1) @@ -36,7 +34,6 @@ def d1_multi_with_as_fallthrough(): print(1) print(2) -# Fails in 3.10, same issue as b def e0_with_multi_as(): with a as b, c: print(1) @@ -46,7 +43,6 @@ def e1_with_multi_as_fallthrough(): print(1) print(2) -# Fails in 3.10, same issue as b def f0_multi_with_multi_as(): with a as b, c as d: print(1) @@ -56,7 +52,6 @@ def f1_multi_with_multi_as_fallthrough(): print(1) print(2) -# Fails in 3.10, same issue as b def g0_multi_with_multi_as_alt(): with a, b as c, d: print(1) @@ -66,7 +61,6 @@ def g1_multi_with_multi_as_fallthrough_alt(): print(1) print(2) -# Fails in 3.13, unexpected JUMP_BACKWARD_NO_INTERRUPT messes up the template def h0_try_with_except(): try: with a: