fix: remove dead guards for Structure without start brace - #436
Draft
toddr-bot wants to merge 2 commits into
Draft
fix: remove dead guards for Structure without start brace#436toddr-bot wants to merge 2 commits into
toddr-bot wants to merge 2 commits into
Conversation
Structures are always constructed with a start brace token, and PDOM manipulation cannot remove it. Multiple places in the code guard against a missing start brace, but these guards are dead code. Add $TODO-marked tests documenting this invariant to prepare for removing the dead guards. See #24 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
PPI::Structure::new() always sets {start} (or returns undef), and PDOM
manipulation cannot remove it since brace tokens are not in {children}.
Code that guarded against a missing start brace was unreachable.
- Structure::braces() no longer checks for missing start
- Structure::complete() simplified to only check finish
- Structure::elements() always includes start in count/list
- Structure::first_element() always returns start
- Structure::content() always uses start->content
- Structure::tokens() always includes start
- Dumper::_element_string() always uses start->content
- Token::Structure::previous_token() simplified for empty structures
- Updated POD to document that start is always present
Fixes #24
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
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
PPI::Structure::new()always sets{start}(or returns undef), and PDOM manipulation cannot remove brace tokens since they live outside{children}. Multiple places in the code guarded against a missing start brace, but these guards were unreachable dead code.This removes the dead guards and updates POD to document that
startis always present.Fixes #24
Changes
braces(),complete(),elements(),first_element(),content(),tokens()inPPI::Structureto not guard against missingstart_element_string()inPPI::Dumperto always usestart->contentprevious_token()inPPI::Token::Structurefor empty structuresstart()andbraces()to reflect thatstartis always definedt/structure_start_brace.twith 49 tests confirming the invariantTest plan
t/structure_start_brace.tverifies:startdefinedbraces()always returns a defined valuefirst_element()always returns the start bracecomplete()method behaviorGenerated by Kōan /fix
Quality Report
Changes: 4 files changed, 87 insertions(+), 33 deletions(-)
Code scan: clean
Tests: skipped
Branch hygiene: clean
Generated by Kōan post-mission quality pipeline