Skip to content

move "illegal anon sub" error from toke.c to perly.y #23519

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: blead
Choose a base branch
from

Conversation

mauke
Copy link
Contributor

@mauke mauke commented Jul 31, 2025

This fixes the TODO test in t/op/anonsub.t, but breaks two other tests:

  • t/op/anonsub.t

      not ok 12 - '{ $x = sub }' is illegal
      # Failed test 12 - '{ $x = sub }' is illegal at t/op/anonsub.t line 15
      #      got 'Global symbol \"$x\" requires explicit package name (did you forget to declare \"my $x\"?) at (eval 12) line 1, <DATA> line 87.\nIllegal declaration of anonymous subroutine at (eval 12) line 1, at EOF\n'
      # expected /(?^:^Illegal declaration of anonymous subroutine at)/
    
  • t/lib/croak.t

      FILE: lib/croak/toke ; line 644
      PROG:
      no feature 'apostrophe_as_package_separator';
      sub 'Hello'_he_said (_);
      EXPECTED:
      Illegal declaration of anonymous subroutine at - line 2.
      EXIT STATUS: != 0
      GOT:
      Bareword found where operator expected (Missing operator before "_he_said"?) at - line 2, near "'Hello'_he_said"
      Illegal declaration of anonymous subroutine at - line 2, near "sub 'Hello'"
      Execution of - aborted due to compilation errors.
      EXIT STATUS: 255
      not ok 247 - tick in names: initial character of sub name (no feature)
      # Failed test 247 - tick in names: initial character of sub name (no feature) at lib/croak/toke line 644
    

Since we don't immediately error out from the lexer anymore, the parser may accumulate more errors before failing with "Illegal declaration of anonymous subroutine".

See #5959.


  • This set of changes requires a perldelta entry, and it is included.
  • This set of changes requires a perldelta entry, and I need help writing it.
  • This set of changes does not require a perldelta entry.

mauke added 2 commits August 3, 2025 13:50
This fixes the TODO test in t/op/anonsub.t, but breaks two other tests:

- t/op/anonsub.t

        not ok 12 - '{ $x = sub }' is illegal
        # Failed test 12 - '{ $x = sub }' is illegal at t/op/anonsub.t line 15
        #      got 'Global symbol \"$x\" requires explicit package name (did you forget to declare \"my $x\"?) at (eval 12) line 1, <DATA> line 87.\nIllegal declaration of anonymous subroutine at (eval 12) line 1, at EOF\n'
        # expected /(?^:^Illegal declaration of anonymous subroutine at)/

- t/lib/croak.t

        FILE: lib/croak/toke ; line 644
        PROG:
        no feature 'apostrophe_as_package_separator';
        sub 'Hello'_he_said (_);
        EXPECTED:
        Illegal declaration of anonymous subroutine at - line 2.
        EXIT STATUS: != 0
        GOT:
        Bareword found where operator expected (Missing operator before "_he_said"?) at - line 2, near "'Hello'_he_said"
        Illegal declaration of anonymous subroutine at - line 2, near "sub 'Hello'"
        Execution of - aborted due to compilation errors.
        EXIT STATUS: 255
        not ok 247 - tick in names: initial character of sub name (no feature)
        # Failed test 247 - tick in names: initial character of sub name (no feature) at lib/croak/toke line 644

Since we don't immediately error out from the lexer anymore, the parser
may accumulate more errors before failing with "Illegal declaration of
anonymous subroutine".

The tests have been changed to accomodate the new diagnostics.

Fixes Perl#5959.
@mauke mauke force-pushed the fix-5959-illegal-anon-sub branch from ed35b0d to e8508b0 Compare August 3, 2025 12:05
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