-
Notifications
You must be signed in to change notification settings - Fork 559
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
Segfault when inheriting from class in unit syntax #20890
Comments
For what it’s worth, this seems to work fine: {
class A;
}
class B :isa(A) { } |
@leonerd, can you take a look at this problem re |
The problem is the class_initfields_cv pointer (which creates the sub that initializes the class fields) isn't created until the end of scope, and in the failing case that is after the In the non-crashing case, the {} around the I'm not sure how this is intended to work, if I do a "statement" package, a block package restores the current class:
but if we do that with class, as with the failing code, the documentation says the class is closed once
what should the current class/package be after the closing brace of
I'd be inclined to simply disallow the statement form. Backtrace with debug info:
|
Nice find. FWIW, I think the statement form is important to have in Perl. Consistency with class A;
class B {} class A {
class B {}
} Which means it should perhaps be a syntax error for B to inherit from A here because the declaration of A is not yet complete by the time the It turns out the second form causes what I expect is the exact same issue without
(Although I wonder if allowing |
For what it's worth, someone asked a related question on Reddit and I provided an answer, linking to this thread. |
Description
A class declared in the “unit” (or “statement”) syntax – i. e. not with a block – cannot be used as the superclass of another class. A segmentation fault occurs when this is attempted. This happens with v5.37.9 as well as blead at 49830b9 (HEAD at time of this writing). The following combination triggers the bug:
(The diagnostics generated by my OS include a stack trace and are appended at the end of this report.)
Steps to Reproduce
perl -Mfeature=class -e 'class A; class B :isa(A) {}'
Expected behaviour
Clean exit.
Perl configuration
Diagnostic report
The text was updated successfully, but these errors were encountered: