Skip to content

fix: hoist our/state declarations in statement modifiers (if/unless)#490

Merged
fglock merged 1 commit intomasterfrom
fix/our-state-statement-modifier
Apr 11, 2026
Merged

fix: hoist our/state declarations in statement modifiers (if/unless)#490
fglock merged 1 commit intomasterfrom
fix/our-state-statement-modifier

Conversation

@fglock
Copy link
Copy Markdown
Owner

@fglock fglock commented Apr 11, 2026

Summary

  • Fix our and state variable declarations with statement modifiers (if/unless)
  • The parser's handleStatementModifierWithMy only handled my declarations, causing our $DEBUG = 0 unless defined $DEBUG to fail under use strict with "Global symbol requires explicit package name"
  • Extended the check to handle my, our, and state uniformly by hoisting the declaration before the condition: our $X = EXPR unless COND(our $X, COND || ($X = EXPR))
  • This unblocks Template Toolkit 3.102, which uses this pattern in 16+ .pm files — Makefile.PL now runs successfully
  • Updated dev/modules/template.md with Fix 10 and current status

Files changed

File Change
StatementResolver.java Extended handleStatementModifierWithMy to handle our/state
statement.t Added 4 tests for our/state with if/unless modifiers
template.md Documented Fix 10 and updated remaining failures section

Test plan

  • make passes (all unit tests green)
  • ./jperl -e 'use strict; our $X = 1 unless defined $X; print "ok\n"' works
  • ./jcpan -t Template gets past Makefile.PL and runs full test suite
  • New unit tests cover our with unless, our with if, our preserving pre-defined values, and state with unless

Note on remaining Template Toolkit failures

After this fix, 85/106 Template Toolkit tests pass. The 21 failing tests are all caused by premature DESTROY firing on Template::Context — a separate refCount tracking issue being fixed on another branch.

Generated with Devin

The parser's handleStatementModifierWithMy only handled 'my' declarations,
not 'our' or 'state'. This caused 'our $DEBUG = 0 unless defined $DEBUG'
to be transformed into 'defined($DEBUG) || (our $DEBUG = 0)', placing the
$DEBUG reference before the our declaration. Under use strict, this produced
"Global symbol requires explicit package name".

The fix extends the check to handle my, our, and state uniformly:
  our $X = EXPR unless COND  ->  (our $X, COND || ($X = EXPR))

This unblocks Template Toolkit 3.102 which uses this pattern in 16 files.

Generated with [Devin](https://cli.devin.ai/docs)

Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
@fglock fglock force-pushed the fix/our-state-statement-modifier branch from 58e3da9 to c8d065d Compare April 11, 2026 11:45
@fglock fglock merged commit e5f57f9 into master Apr 11, 2026
2 checks passed
@fglock fglock deleted the fix/our-state-statement-modifier branch April 11, 2026 11:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant