Skip to content

Commit 436f980

Browse files
committed
Fix stale marker bug in labeled blocks
Root cause: Labeled blocks were not clearing the RuntimeControlFlowRegistry when they exited, causing stale markers to affect subsequent labeled blocks. This caused uni/variables.t to stop at test 56 because an eval with a labeled block left a marker that interfered with later SKIP blocks. Fix: Clear the registry when exiting any labeled block. Changes: - EmitBlock.java: Call RuntimeControlFlowRegistry.clear() when exiting labeled blocks - skip_control_flow.t: Add test case #10 for stale marker bug Results: - skip_control_flow.t: all 10 tests pass ✓ - uni/variables.t: 66683/66880 (baseline maintained) ✓ - op/pack.t: baseline maintained ✓ - make: BUILD SUCCESSFUL ✓
1 parent e93244a commit 436f980

File tree

3 files changed

+31
-0
lines changed

3 files changed

+31
-0
lines changed

.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,11 @@ logs/
4949
.perlonjava_env_ready
5050
*.diff
5151
*.patch
52+
53+
.windsurf/
54+
Image-ExifTool-13.44/
55+
dev/examples/DiagnoseBytecodeEstimation.pl
56+
dev/prompts/fix_pat_advanced_verifyerror.md
5257
# But allow patch files in import-perl5/patches/
5358
!dev/import-perl5/patches/*.patch
5459

src/main/java/org/perlonjava/codegen/EmitBlock.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,16 @@ public static void emitBlock(EmitterVisitor emitterVisitor, BlockNode node) {
150150

151151
if (node.isLoop) {
152152
emitterVisitor.ctx.javaClassInfo.popLoopLabels();
153+
154+
// Clear any stale markers when exiting a labeled block
155+
// This prevents markers from affecting subsequent labeled blocks
156+
if (node.labelName != null) {
157+
mv.visitMethodInsn(Opcodes.INVOKESTATIC,
158+
"org/perlonjava/runtime/RuntimeControlFlowRegistry",
159+
"clear",
160+
"()V",
161+
false);
162+
}
153163
}
154164

155165
// Pop labels used inside the block

src/test/resources/unit/skip_control_flow.t

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,4 +133,20 @@ sub ok_tap {
133133
ok_tap($out eq 'AC', 'last LABEL3 exits LABEL3 block (2 frames, void context)');
134134
}
135135

136+
# 10) Stale marker bug - labeled block in eval leaves marker
137+
{
138+
my $out = '';
139+
# This eval creates a labeled block that might leave a stale marker
140+
eval "\${\x{30cd}single:\x{30cd}colon} = 'test'";
141+
$out .= 'A';
142+
143+
# This SKIP block should work normally, not be affected by stale marker
144+
MYLABEL: {
145+
$out .= 'B';
146+
$out .= 'C';
147+
}
148+
$out .= 'D';
149+
ok_tap($out eq 'ABCD', 'labeled block in eval does not leave stale marker');
150+
}
151+
136152
print "1..$t\n";

0 commit comments

Comments
 (0)