Fix goto LABEL resolution in loop bodies under subtest#177
Closed
Fix goto LABEL resolution in loop bodies under subtest#177
Conversation
543523e to
5a1dbd7
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Enabling the upstream/original
Test::More(fromTest-Simple) causedsrc/test/resources/unit/control_flow.tto fail insidesubtestwith:Can't find label NEXT at ... control_flow.t line 201This PR fixes local label resolution for
goto LABELinside loop-body blocks by ensuring loop body labels are registered ingotoLabelStackwhile emitting the loop body.Problem Details
Reproducer
Root cause
EmitControlFlow.handleGotoLabel()determines whethergoto LABELis local via:ctx.javaClassInfo.findGotoLabelsByName(labelName)The failing construct parses such that the label is scoped to the loop body block:
For1Node.Body.BlockNode.labels: NEXTLabelNode: NEXT:However,
EmitForeach.emitFor1()emitted the loop body statements directly without registering any goto labels for that bodyBlockNode. As a result,goto NEXTwas treated as non-local and eventually raised an uncaught marker error.Why upstream
Test::Moreexposes thisUpstream
Test::Morerunssubtestbodies viaTest::Builder->subtest, wraps the callback in aneval, and thendies if it failed. This makes label-resolution failures inside subtests fatal and aborts the test file beforedone_testing().Changes
1) Register loop-body goto labels in
EmitForeachFile:
src/main/java/org/perlonjava/codegen/EmitForeach.javaBlockNode.For1Node.bodyis aBlockNode, push labels before emitting statements and pop them after.This makes forward and backward
goto LABELwork correctly inside loop bodies.2) Pre-register statement labels in
EmitBlockFile:
src/main/java/org/perlonjava/codegen/EmitBlock.javaLabelNodestatement labels for blocks emitted viaEmitBlock.3) Enable upstream Test::More import
Files:
dev/import-perl5/config.yamlsrc/main/perl/lib/Test/More.pmThis switches
Test::Moreto the upstream/original code path that surfaced the issue.Tests
makepasses./jperl src/test/resources/unit/control_flow.tpassesNotes
goto LABELresolution during compilation.goto EXPR(computed labels), which remains skipped incontrol_flow.t.