Skip to content

fix: fix three bugs causing Parse::Yapp test failures#505

Merged
fglock merged 2 commits intomasterfrom
fix/parse-yapp-test-failures
Apr 13, 2026
Merged

fix: fix three bugs causing Parse::Yapp test failures#505
fglock merged 2 commits intomasterfrom
fix/parse-yapp-test-failures

Conversation

@fglock
Copy link
Copy Markdown
Owner

@fglock fglock commented Apr 13, 2026

Summary

Fixes three bugs that caused Parse::Yapp test failures when run via jcpan -t Parse::Yapp:

Bug 1: Indirect object notation with eval-created classes

  • File: SubroutineParser.java
  • new Test(yylex => $lex) failed when Test was created via eval (not known at compile time)
  • Fixed by only rejecting indirect object syntax when the method name IS a known function

Bug 2: pack('b'.$n) with no data arguments

  • File: PackWriter.java
  • pack('b825') returned empty string instead of 104 zero-filled bytes (ceil(825/8))
  • Added zero-padding loop to fill to the correct byte count

Bug 3: Bitwise operator string/numeric dispatch (root cause of stress.t failure)

  • File: BitwiseOperators.java
  • Replaced looksLikeNumber() heuristic with type-based dispatch matching Perl 5 semantics (SvNIOKp)
  • Bitwise &, |, ^, ~ now use the numeric path only when either operand has a native numeric type (INTEGER/DOUBLE), and the string path when both are non-numeric
  • This fixes:
    • $s |= $s corruption on pack/vec strings (the _Digraph function in Parse::Yapp::Lalr depends on this)
    • "05" | "03" now correctly returns "07" (string OR) instead of 7 (numeric OR)

Test plan

  • make passes (all unit tests)
  • jcpan -t Parse::Yapp — all 3 test files pass (t/base.t, t/calc.t, t/stress.t)
  • Verified bitwise operator behavior matches Perl 5 for string-string, numeric-numeric, and mixed cases

Generated with Devin

fglock and others added 2 commits April 13, 2026 17:03
1. Indirect object notation: Allow `new Class(args)` when Class is
   not known at compile time (e.g., created via eval). Fixed by only
   rejecting indirect object syntax when the method IS a known function.

2. pack('b'.$n) zero-fill: pack with bit template and no data args
   now correctly returns zero-filled bytes (ceil(count/8)) instead of
   an empty string.

3. Bitwise operator string/numeric dispatch: Replace looksLikeNumber()
   heuristic with type-based dispatch matching Perl 5 semantics (SvNIOKp).
   Bitwise ops now use numeric path only when either operand has a native
   numeric type (INTEGER/DOUBLE), and string path when both are strings.
   This fixes corruption of pack/vec strings by $s |= $s and also fixes
   "05" | "03" to correctly return "07" (string OR) instead of 7.

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

Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
The bitwise dispatch change (type-based instead of looksLikeNumber)
caused a regression in op/bop.t: binary&=, binary|=, binary^= (from
use feature "bitwise") were sharing opcodes with the regular &=, |=, ^=
which now use type-based dispatch. Under the bitwise feature, these
must always use numeric operations regardless of operand type.

Fix: add dedicated BINARY_AND_ASSIGN/OR/XOR opcodes (468-470) and
route binary&/|/^ to BINARY_AND/OR/XOR opcodes that call the
always-numeric bitwiseAndBinary/OrBinary/XorBinary directly.

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/parse-yapp-test-failures branch from d594b98 to b75d5e0 Compare April 13, 2026 15:04
@fglock fglock merged commit 8e15479 into master Apr 13, 2026
2 checks passed
@fglock fglock deleted the fix/parse-yapp-test-failures branch April 13, 2026 15:13
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