Skip to content

fix: remove dead guards for Structure without start brace - #436

Draft
toddr-bot wants to merge 2 commits into
masterfrom
koan.toddr.bot/fix-issue-24
Draft

fix: remove dead guards for Structure without start brace#436
toddr-bot wants to merge 2 commits into
masterfrom
koan.toddr.bot/fix-issue-24

Conversation

@toddr-bot

@toddr-bot toddr-bot commented Apr 27, 2026

Copy link
Copy Markdown
Collaborator

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 start is always present.

Fixes #24

Changes

  • Simplified braces(), complete(), elements(), first_element(), content(), tokens() in PPI::Structure to not guard against missing start
  • Simplified _element_string() in PPI::Dumper to always use start->content
  • Simplified previous_token() in PPI::Token::Structure for empty structures
  • Updated POD for start() and braces() to reflect that start is always defined
  • Added t/structure_start_brace.t with 49 tests confirming the invariant

Test plan

  • New test file t/structure_start_brace.t verifies:
    • Every Structure from parsing always has start defined
    • braces() always returns a defined value
    • first_element() always returns the start brace
    • Both complete and incomplete (missing finish brace) documents
    • complete() method behavior
  • Full test suite passes (70 files, 53140 tests, 0 failures)

Generated 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

toddr-bot and others added 2 commits April 27, 2026 09:13
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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

what is a structure without braces?

2 participants