Skip to content

class :isa does not require parent class with hierarchical naming #21332

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

Closed
ntyni opened this issue Aug 7, 2023 · 0 comments · Fixed by #21359
Closed

class :isa does not require parent class with hierarchical naming #21332

ntyni opened this issue Aug 7, 2023 · 0 comments · Fixed by #21359

Comments

@ntyni
Copy link
Contributor

ntyni commented Aug 7, 2023

This is a bug report for perl from [email protected],
generated with the help of perlbug 1.43 running under perl 5.39.2.


Description

If the class A::B inherits A with 'class A::B :isa(A)', A.pm does not
get loaded/required. This seems to be because of the hierarchical naming:
class B :isa(A) loads A.pm just fine.

I don't see a mention of this in the documentation, and Object::Pad
does not exhibit the same behaviour FWIW.

Explicitly loading A first (with e.g. 'use A') seems to be a workaround.

Steps to Reproduce

% cat lib/A.pm
use feature 'class';
class A {};
1;
% cat lib/A/B.pm
use feature 'class';
class A::B :isa(A) {};
1;
% perl -Ilib -c lib/A/B.pm; echo $?
class is experimental at lib/A/B.pm line 2.
Class :isa attribute requires a class but "A" is not one at lib/A/B.pm line 2.
255

Expected behavior
A.pm should get loaded as described in perlclass.pod for :isa().


Flags

  • category=core
  • severity=low

Perl configuration

Site configuration information for perl 5.39.2:

Configured by ntyni at Mon Aug	7 18:05:37 BST 2023.

Summary of my perl5 (revision 5 version 39 subversion 2) configuration:
  Commit id: 4f06424962ba637e7daad1d020cdd9573a9acdda
  Platform:
    osname=linux
    osvers=6.1.0-3-amd64
    archname=x86_64-linux
    uname='linux carme 6.1.0-3-amd64 #1 smp preempt_dynamic debian 6.1.8-1 (2023-01-29) x86_64 gnulinux '
    config_args='-des -Dusedevel'
    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 ='-fwrapv -fno-strict-aliasing -pipe -fstack-protector-strong -I/usr/local/include -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -D_FORTIFY_SOURCE=2'
    optimize='-O2'
    cppflags='-fwrapv -fno-strict-aliasing -pipe -fstack-protector-strong -I/usr/local/include'
    ccversion=''
    gccversion='12.2.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='cc'
    ldflags =' -fstack-protector-strong -L/usr/local/lib'
    libpth=/usr/local/lib /usr/lib/x86_64-linux-gnu /usr/lib /usr/lib64
    libs=-lpthread -lgdbm -ldb -ldl -lm -lcrypt -lutil -lc -lgdbm_compat
    perllibs=-lpthread -ldl -lm -lcrypt -lutil -lc
    libc=/lib/x86_64-linux-gnu/libc.so.6
    so=so
    useshrplib=false
    libperl=libperl.a
    gnulibc_version='2.36'
  Dynamic Linking:
    dlsrc=dl_dlopen.xs
    dlext=so
    d_dlsymun=undef
    ccdlflags='-Wl,-E'
    cccdlflags='-fPIC'
    lddlflags='-shared -O2 -L/usr/local/lib -fstack-protector-strong'


---
@INC for perl 5.39.2:
    lib
    /usr/local/lib/perl5/site_perl/5.39.2/x86_64-linux
    /usr/local/lib/perl5/site_perl/5.39.2
    /usr/local/lib/perl5/5.39.2/x86_64-linux
    /usr/local/lib/perl5/5.39.2

---
Environment for perl 5.39.2:
    HOME=/home/ntyni
    LANG=C
    LANGUAGE (unset)
    LC_CTYPE=fi_FI.UTF-8
    LD_LIBRARY_PATH (unset)
    LOGDIR (unset)
    PATH=/usr/local/bin:/usr/bin:/bin:/usr/games
    PERL_BADLANG (unset)
    SHELL=/bin/zsh
tonycoz added a commit to tonycoz/perl5 that referenced this issue Aug 10, 2023
If class Foo::Bar exists then the Foo stash exists, so checking
for that when Foo is the requested base class is meaningless.

Instead try to load the base class if it is not known as a class, not
just if it's not a stash, just as we do immediately following.

Fixes Perl#21332
tonycoz added a commit that referenced this issue Aug 14, 2023
If class Foo::Bar exists then the Foo stash exists, so checking
for that when Foo is the requested base class is meaningless.

Instead try to load the base class if it is not known as a class, not
just if it's not a stash, just as we do immediately following.

Fixes #21332
sir-xw pushed a commit to openkylin/libstring-license-perl that referenced this issue Apr 18, 2025
__CLASS__ is not implemented in 5.38 yet, so we need to use Object::Pad
for String::License instead of Feature::Compat::Class.

Hierarchical naming currently has a quirk with :isa(), see
Perl/perl5#21332

Bug-Debian: https://bugs.debian.org/1042847
Bug: https://rt.cpan.org/Ticket/Display.html?id=148507

Gbp-Pq: Name 0001-Workarounds-for-the-class-feature-on-Perl-5.38.patch
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 a pull request may close this issue.

2 participants