Skip to content

&CORE::__CLASS__ returns bogus value (filename) #23737

Description

@mauke

Description

&CORE::__CLASS__ should either fail cleanly (Undefined subroutine &CORE::__CLASS__ called or similar) or work and return a class name. Instead it returns the caller's filename.

Steps to Reproduce

use v5.36;
use experimental qw(class);

class Foo {
    method f1() { __CLASS__ }
    method f2() { &CORE::__CLASS__() }
    method f3() { \&CORE::__CLASS__ }
}

my $o = Foo->new;

say $o->f1;
say $o->f2;
say $o->f3->();

Output:

Foo
bug.pl
bug.pl

Expected behavior

Foo
Foo
Foo

... actually I'm not sure about the third one. I think that ought to be a runtime error, maybe?

Activity

  1. added theissue type on Sep 19, 2025
  2. jkeenan commented on Sep 19, 2025

    @jkeenan
    Contributor

    Your program starts with use v5.36;. That suggested to me that I should try to run it with my perlbrew-installed perl-5.36.0 -- but I got exception there and at 5.38 as well.

    $ perlbrew use perl-5.36.0
    $ perl gh-23737-class.pl 
    Can't enable unknown feature class at gh-23737-class.pl line 4.
    BEGIN failed--compilation aborted at gh-23737-class.pl line 4.
    
    $ perlbrew use perl-5.38.0
    $ perl gh-23737-class.pl 
    Bareword "__CLASS__" not allowed while "strict subs" in use at gh-23737-class.pl line 7.
    Execution of gh-23737-class.pl aborted due to compilation errors.
    

    I had to use 5.40 to get it to DWIM.

    $ perlbrew use perl-5.40.1
    $ perl gh-23737-class.pl 
    Foo
    gh-23737-class.pl
    gh-23737-class.pl
    

    Am I missing something?

  3. mauke commented on Sep 19, 2025

    @mauke
    ContributorAuthor

    That suggested to me that I should try to run it with my perlbrew-installed perl-5.36.0

    Not my intention. My "default script template" starts with use v5.36 to enable strict/warnings/modern features with a single line of code, but any additional features (such as class) may require a newer perl (5.40.0 in this case).

  4. added a commit that references this issue on Sep 20, 2025
    38d8562
  5. added a commit that references this issue on Sep 22, 2025
    7e96be5
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions