Skip to content

class feature: Anonymous methods can't access fields #23446

@ivrntsv

Description

@ivrntsv

Description
I'm not sure if they should, but, maybe, someone knows better.

Steps to Reproduce
perl -Mexperimental=class -e 'class Foo; field $foo = 42; use overload q{""} => method (@) { $foo }'
gives
Field $foo is not accessible outside a method at -e line 1.

Perl configuration

Summary of my perl5 (revision 5 version 42 subversion 0) configuration:
   
  Platform:
    osname=cygwin
    osvers=3.6.3-bc3e285a.x86_64
    archname=x86_64-cygwin
    uname='cygwin_nt-10.0-19045 desktop-97pareg 3.6.3-bc3e285a.x86_64 2025-06-23 18:27 utc x86_64 cygwin '
    config_args='-des -Uusethreads -Dfirstmakefile=GNUmakefile -Doptimize=-march=nocona -msahf -mtune=generic -O2 -pipe -Dprefix=/usr -Dprivlib=/usr/share/perl/core -Darchlib=/usr/lib/perl/core -Dsitelib=/usr/share/perl/site -Dsitearch=/usr/lib/perl/site -Dinc_version_list=none -Dman1dir=none -Dman3dir=none -Darchname=x86_64-cygwin -Dlibperl=msys-perl5_42.dll -Dcc=gcc -Dld=g++ -Accflags=-march=nocona -msahf -mtune=generic -O2 -pipe -DNO_TAINT_SUPPORT -fwrapv'
    hint=recommended
    useposix=true
    d_sigaction=define
    useithreads=undef
    usemultiplicity=undef
    use64bitint=define
    use64bitall=define
    uselongdouble=undef
    usemymalloc=n
    default_inc_excludes_dot=define
  Compiler:
    cc='gcc'
    ccflags ='-D_GNU_SOURCE -march=nocona -msahf -mtune=generic -O2 -pipe -DNO_TAINT_SUPPORT -fwrapv -fno-strict-aliasing -fstack-protector-strong -D_FORTIFY_SOURCE=2'
    optimize='-march=nocona -msahf -mtune=generic -O2 -pipe'
    cppflags='-D_GNU_SOURCE -march=nocona -msahf -mtune=generic -O2 -pipe -DNO_TAINT_SUPPORT -fwrapv -fno-strict-aliasing -fstack-protector-strong'
    ccversion=''
    gccversion='13.4.0'
    gccosandvers=''
    intsize=4
    longsize=8
    ptrsize=8
    doublesize=8
    byteorder=12345678
    doublekind=3
    d_longlong=define
    longlongsize=8
    d_longdbl=define
    longdblsize=16
    longdblkind=3
    ivtype='long'
    ivsize=8
    nvtype='double'
    nvsize=8
    Off_t='off_t'
    lseeksize=8
    alignbytes=8
    prototype=define
  Linker and Libraries:
    ld='g++'
    ldflags =' -Wl,--enable-auto-import -Wl,--export-all-symbols -Wl,--enable-auto-image-base -fstack-protector-strong'
    libpth=/usr/lib /usr/lib/w32api
    libs=-lpthread -lgdbm -ldb -ldl -lcrypt -lgdbm_compat
    perllibs=-lpthread -ldl -lcrypt
    libc=/usr/lib/libcygwin.a
    so=dll
    useshrplib=true
    libperl=msys-perl5_42.dll
    gnulibc_version=''
  Dynamic Linking:
    dlsrc=dl_dlopen.xs
    dlext=dll
    d_dlsymun=undef
    ccdlflags=' '
    cccdlflags=' '
    lddlflags=' --shared  -Wl,--enable-auto-import -Wl,--export-all-symbols -Wl,--enable-auto-image-base -fstack-protector-strong'


Characteristics of this binary (from libperl): 
  Compile-time options:
    HAS_LONG_DOUBLE
    HAS_STRTOLD
    HAS_TIMES
    NO_TAINT_SUPPORT
    PERLIO_LAYERS
    PERL_COPY_ON_WRITE
    PERL_DONT_CREATE_GVSV
    PERL_HASH_FUNC_SIPHASH13
    PERL_HASH_USE_SBOX32
    PERL_OP_PARENT
    PERL_PRESERVE_IVUV
    PERL_USE_SAFE_PUTENV
    USE_64_BIT_ALL
    USE_64_BIT_INT
    USE_LARGE_FILES
    USE_LOCALE
    USE_LOCALE_COLLATE
    USE_LOCALE_CTYPE
    USE_LOCALE_NUMERIC
    USE_LOCALE_TIME
    USE_PERLIO
    USE_PERL_ATOF
  Built under cygwin
  Compiled at Jul  3 2025 16:25:50
  %ENV:
    PERLLIB="/home/iv/.my/perl"
  @INC:
    /home/iv/.my/perl
    /usr/lib/perl/site
    /usr/share/perl/site
    /usr/lib/perl/core
    /usr/share/perl/core

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugclassIssues related to 'class' keyword or __CLASS__

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions