Skip to content

Fix bytecode compiler my-extraction and AUTOLOAD with forward declarations#244

Merged
fglock merged 1 commit intomasterfrom
fix-bytecode-my-extraction
Feb 26, 2026
Merged

Fix bytecode compiler my-extraction and AUTOLOAD with forward declarations#244
fglock merged 1 commit intomasterfrom
fix-bytecode-my-extraction

Conversation

@fglock
Copy link
Owner

@fglock fglock commented Feb 26, 2026

Summary

Relates to #93

Two fixes that improve ExifTool compatibility from 12/35 to 24/35 passing tests.

1. Bytecode compiler: my extraction in short-circuit operators

The bytecode compiler (interpreter backend) for &&, ||, and // operators now extracts my declarations before the short-circuit jump. Previously, my $x = expr if COND left the interpreter register as Java null when the condition was false, causing NPEs at runtime.

Now uses FindDeclarationVisitor to emit the declaration unconditionally before the conditional jump, matching the JVM emitter behavior that was fixed in PR #243.

2. AUTOLOAD with forward declarations

Forward declarations (sub foo;) no longer prevent AUTOLOAD from being called during method dispatch. Previously, findMethodInHierarchy would find the forward declaration, see it was undefined, and continue to the next class in the hierarchy — bypassing the AUTOLOAD check for the current class.

Now it falls through to the AUTOLOAD check for the same class. This fixes ExifTool's VerboseInfo and other Writer.pl methods that are loaded via AUTOLOAD.

ExifTool.t results

Before: 12/35 tests pass, crashes at test 17 (VerboseInfo not found)
After: 24/35 tests pass, all 35 tests run to completion

Remaining 11 failures are mostly related to missing File System metadata (FileSize, FileModifyDate, FilePermissions).

Test plan

  • ./gradlew test passes (all unit tests)
  • my $x = expr if COND works in both JVM and interpreter paths
  • Forward declarations fall through to AUTOLOAD correctly
  • ExifTool.t runs all 35 tests without crashes

Generated with Devin

… with forward declarations

Two fixes:

1. Bytecode compiler (interpreter backend): extract my declarations
   before short-circuit jumps in &&/||// operators. Previously,
   'my $x = expr if COND' left the register as Java null when the
   condition was false, causing NPEs. Now uses FindDeclarationVisitor
   to emit the declaration unconditionally before the conditional jump,
   matching the JVM emitter behavior.

2. Method resolution: forward declarations (sub foo;) no longer prevent
   AUTOLOAD from being called. Previously, findMethodInHierarchy would
   find the forward declaration, see it was undefined, and skip to the
   next class in the hierarchy (bypassing AUTOLOAD). Now it falls
   through to the AUTOLOAD check for the same class. This fixes
   ExifTool VerboseInfo and other Writer.pl methods loaded via AUTOLOAD.

ExifTool.t: 24/35 tests pass (up from 12/35, test 17 no longer crashes).

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

Co-Authored-By: Devin <noreply@cognition.ai>
@fglock fglock merged commit 93fce6a into master Feb 26, 2026
2 checks passed
@fglock fglock deleted the fix-bytecode-my-extraction branch February 26, 2026 21:23
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