Skip to content

Improve parser error messages to pass more croak.t tests (11→44/330)#273

Merged
fglock merged 2 commits into
masterfrom
improve-croak-error-messages
Mar 6, 2026
Merged

Improve parser error messages to pass more croak.t tests (11→44/330)#273
fglock merged 2 commits into
masterfrom
improve-croak-error-messages

Conversation

@fglock
Copy link
Copy Markdown
Owner

@fglock fglock commented Mar 6, 2026

Summary

Improves PerlOnJava's parser error messages to more closely match Perl 5's format, increasing perl5_t/t/lib/croak.t from 11/330 to 44/330 passing tests (4x improvement).

Error message formatting (ErrorMessageUtil.java)

  • Rewrite buildNearString() to show forward from error position, stop at block delimiters ({/}), and preserve trailing whitespace for Perl compatibility
  • Use getSourceLocationAccurate() in throwError for correct #line directive handling
  • Add throwError(int index, String message) overload for precise error position control
  • Send compilation errors to stderr instead of stdout (Main.java)

Signature validation (SignatureParser.java)

  • Add "A slurpy parameter may not have a default value" check
  • Add "Mandatory parameter follows optional parameter" check
  • Add "Illegal operator following parameter in a subroutine signature" check
  • Add "Can't use global $_/@_/%_ in subroutine signature" check
  • Fix text: "Named parameters must actually have a name" (matches Perl 5)

New parser error messages

  • Add $# is no longer supported as of Perl 5.30 (Variable.java)
  • Add $* is no longer supported as of Perl 5.30 (ParsePrimary.java)

Token position fixes

  • Save firstArgIndex before list parsing for push/unshift errors
  • Use paramStartIndex for signature parameter position errors

Test plan

  • All 156 unit tests pass (mvn test)
  • croak.t passes 44/330 tests (up from 11/330 baseline)
  • No regressions in existing test suite

Generated with Devin

fglock and others added 2 commits March 6, 2026 10:29
Error message formatting:
- Rewrite buildNearString() to show forward from error position, stop at
  block delimiters ({/}), and preserve trailing whitespace for Perl compat
- Use getSourceLocationAccurate() in throwError for correct #line handling
- Add throwError(int index, String message) overload for precise positioning
- Send compilation errors to stderr instead of stdout in Main.java

Signature validation (SignatureParser.java):
- Add "A slurpy parameter may not have a default value" check
- Add "Mandatory parameter follows optional parameter" check
- Add "Illegal operator following parameter in a subroutine signature" check
- Add "Can't use global $_/@_/%_ in subroutine signature" check
- Fix text: "Named parameters must actually have a name" (matches Perl)

New parser error messages:
- Add "$# is no longer supported as of Perl 5.30" (Variable.java)
- Add "$* is no longer supported as of Perl 5.30" (ParsePrimary.java)

Token position fixes:
- Save firstArgIndex before list parsing for push/unshift errors
- Use paramStartIndex for signature parameter position errors

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

Co-Authored-By: Devin <noreply@cognition.ai>
The bare $# deprecation check was too aggressive, triggering on valid
uses like $#+ ($#LAST_MATCH_END), $#- ($#LAST_MATCH_START), and
$#{^CAPTURE}. Add +, -, and ^ to the list of valid tokens after $#.

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

Co-Authored-By: Devin <noreply@cognition.ai>
@fglock fglock merged commit 7093911 into master Mar 6, 2026
2 checks passed
@fglock fglock deleted the improve-croak-error-messages branch March 6, 2026 09:58
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