Skip to content

class feature: Segfault during syntax check with class field attributes and undefined variable #23839

@kfly8

Description

@kfly8

Module: class feature

Description

Segmentation fault occurs when running syntax check (perl -wc) on a script that combines:

  1. Experimental class feature with field attributes (:reader or :writer)
  2. An undefined global variable (e.g., @ARG)

Expected behavior is a syntax error message, but instead Perl crashes with a segfault.

Note: The segfault only occurs when field attributes like :reader or :writer are present. Without these attributes, the expected syntax error is properly reported.

Steps to Reproduce

Create a file a.pl with the following content:

use strict;
use warnings;
use experimental qw(class);

print @ARG;

class MyClass {
  field $message :param :reader;
}

Then run:
perl -wc a.pl

Expected behavior

Should display a syntax error:
Global symbol "@ARG" requires explicit package name at a.pl line 5.
a.pl had compilation errors.

Actual behavior

Segmentation fault occurs instead of the syntax error message.

Perl configuration

Summary of my perl5 (revision 5 version 42 subversion 0) configuration:
   
  Platform:
    osname=darwin
    osvers=23.5.0
    archname=darwin-2level
    uname='darwin kfly8.local 23.5.0 darwin kernel version 23.5.0: wed may 1 20:14:38 pdt 2024; root:xnu-10063.121.3~5release_arm64_t6020 arm64 '
    config_args='-des -Dprefix=/Users/kfly8/.local/share/mise/installs/perl/5.42.0 -Dscriptdir=/Users/kfly8/.local/share/mise/installs/perl/5.42.0/bin -Dman1dir=none -Dman3dir=none'
    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='cc'
    ccflags ='-fno-common -DPERL_DARWIN -DNO_THREAD_SAFE_QUERYLOCALE -DNO_POSIX_2008_LOCALE -DHAS_BROKEN_LANGINFO_CODESET -fno-strict-aliasing -pipe -fstack-protector-strong'
    optimize='-O3'
    cppflags='-fno-common -DPERL_DARWIN -DNO_THREAD_SAFE_QUERYLOCALE -DNO_POSIX_2008_LOCALE -DHAS_BROKEN_LANGINFO_CODESET -fno-strict-aliasing -pipe -fstack-protector-strong'
    ccversion=''
    gccversion='Apple LLVM 16.0.0 (clang-1600.0.26.4)'
    gccosandvers=''
    intsize=4
    longsize=8
    ptrsize=8
    doublesize=8
    byteorder=12345678
    doublekind=3
    d_longlong=define
    longlongsize=8
    d_longdbl=define
    longdblsize=8
    longdblkind=0
    ivtype='long'
    ivsize=8
    nvtype='double'
    nvsize=8
    Off_t='off_t'
    lseeksize=8
    alignbytes=8
    prototype=define
  Linker and Libraries:
    ld='cc'
    ldflags =' -fstack-protector-strong -L/usr/local/lib'
    libpth=/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/clang/16/lib /Library/Developer/CommandLineTools/SDKs/MacOSX14.5.sdk/usr/lib /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib /usr/local/lib /usr/lib
    libs= 
    perllibs=
    libc=
    so=dylib
    useshrplib=false
    libperl=libperl.a
    gnulibc_version=''
  Dynamic Linking:
    dlsrc=dl_dlopen.xs
    dlext=bundle
    d_dlsymun=undef
    ccdlflags=' '
    cccdlflags=' '
    lddlflags='-bundle -undefined dynamic_lookup -L/usr/local/lib -fstack-protector-strong'


Characteristics of this binary (from libperl): 
  Compile-time options:
    HAS_LONG_DOUBLE
    HAS_STRTOLD
    HAS_TIMES
    PERLIO_LAYERS
    PERL_COPY_ON_WRITE
    PERL_DONT_CREATE_GVSV
    PERL_HASH_FUNC_SIPHASH13
    PERL_HASH_USE_SBOX32
    PERL_MALLOC_WRAP
    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 darwin
  Compiled at Jul  4 2025 18:48:07
  @INC:
    /Users/kfly8/.local/share/mise/installs/perl/5.42.0/lib/site_perl/5.42.0/darwin-2level
    /Users/kfly8/.local/share/mise/installs/perl/5.42.0/lib/site_perl/5.42.0
    /Users/kfly8/.local/share/mise/installs/perl/5.42.0/lib/5.42.0/darwin-2level
    /Users/kfly8/.local/share/mise/installs/perl/5.42.0/lib/5.42.0

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions