Skip to content

Fix caller() line number bug for deferred subroutine compilation#336

Merged
fglock merged 3 commits into
masterfrom
feature/update-design-docs
Mar 19, 2026
Merged

Fix caller() line number bug for deferred subroutine compilation#336
fglock merged 3 commits into
masterfrom
feature/update-design-docs

Conversation

@fglock
Copy link
Copy Markdown
Owner

@fglock fglock commented Mar 19, 2026

Summary

  • Fix caller() returning wrong line numbers (end-of-file instead of actual call site)
  • Verify and update design documents for Log4perl and CPAN client compatibility

Changes

caller() Line Number Fix

Root cause: ByteCodeSourceMapper.saveSourceLocation() used getLineNumber() which has a forward-only cache. When subroutines are compiled out-of-order (deferred closure compilation), the cache returned stale values from the end of the file.

Fix: Changed to getLineNumberAccurate() which always counts from the beginning, safe for random access.

Results

Metric Before After
Log::Log4perl subtests failing 18/700 11/700
t/024WarnDieCarp.t failures 8 1

Files Changed

  • src/main/java/org/perlonjava/backend/jvm/ByteCodeSourceMapper.java - The fix
  • src/test/resources/unit/caller_line_number.t - Unit tests (8 tests)
  • dev/design/caller_line_number_fix.md - Detailed design document
  • dev/design/log4perl-compatibility.md - Updated status
  • dev/design/cpan_client.md - Verified status

Test Plan

  • Unit tests pass: ./jperl src/test/resources/unit/caller_line_number.t
  • Full test suite passes: make
  • Log::Log4perl tests improved: ./jcpan -t Log::Log4perl

Generated with Devin

fglock and others added 3 commits March 19, 2026 12:51
Both documents verified against current test results:
- Log::Log4perl: 18/700 subtests failing (6/73 programs)
- CPAN client: Phase 9 complete, jcpan fully functional

All remaining Log4perl failures are documented architectural limitations
(caller line numbers, DESTROY, Safe.pm, source filters).

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

Co-Authored-By: Devin <noreply@cognition.ai>
Root cause: ByteCodeSourceMapper.saveSourceLocation() used getLineNumber()
which has a forward-only cache that returns stale values for out-of-order
token access during deferred subroutine compilation.

Fix: Use getLineNumberAccurate() which always counts from file start,
safe for random access.

Results:
- Log::Log4perl t/024WarnDieCarp.t: 8 failures → 1 failure
- Total Log4perl failures: 18/700 → 11/700 subtests

Files:
- ByteCodeSourceMapper.java: Use accurate line number calculation
- caller_line_number_fix.md: Detailed design document
- caller_line_number.t: Unit tests for caller() line numbers
- log4perl-compatibility.md: Updated status

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

Co-Authored-By: Devin <noreply@cognition.ai>
Generated with [Devin](https://cli.devin.ai/docs)

Co-Authored-By: Devin <noreply@cognition.ai>
@fglock fglock merged commit a0de456 into master Mar 19, 2026
2 checks passed
@fglock fglock deleted the feature/update-design-docs branch March 19, 2026 12:45
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