Skip to content

Conversation

@fglock
Copy link
Owner

@fglock fglock commented Dec 18, 2025

Problem

%{expr} was incorrectly parsed as an infix modulo operator when used as an argument to functions like say. For example:

say %{sub {{ a => 3 }}->()}

was parsed as (say $_) % {hash_literal} instead of say(%{sub...->()}), producing:

  • "Odd number of elements in anonymous hash" warning
  • Empty output

Fix

Added { to the lookahead check in looksLikeEmptyList() so that %{...} and @{...} are recognized as hash/array dereferences rather than infix operators.

Testing

  • ./jperl -E 'say %{sub {{ a => 3 }}->()}' now correctly outputs a3 (matching Perl behavior)
  • All unit tests pass

Context

This fix is needed for JPERL_LARGECODE=refactor which generates constructs like %{sub{...}->()} to wrap large hash literals.

Previously, %{expr} was incorrectly parsed as an infix modulo operator
when used as an argument to functions like 'say'. For example:
  say %{sub {{ a => 3 }}->()}
was parsed as (say ) % {hash_literal} instead of say(%{sub...->()}).

The fix adds '{' to the lookahead check in looksLikeEmptyList() so that
%{...} and @{...} are recognized as hash/array dereferences rather than
infix operators.

This is needed for JPERL_LARGECODE=refactor which generates constructs
like %{sub{...}->()}.
@fglock fglock merged commit ccd2908 into master Dec 18, 2025
3 of 4 checks passed
@fglock fglock deleted the fix-hash-deref-parsing branch December 18, 2025 15:09
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.

2 participants