Skip to content

class.c: delay declaring $self until after block_start() - #24738

Open
leonerd wants to merge 1 commit into
Perl:bleadfrom
leonerd:gh24610
Open

class.c: delay declaring $self until after block_start()#24738
leonerd wants to merge 1 commit into
Perl:bleadfrom
leonerd:gh24610

Conversation

@leonerd

@leonerd leonerd commented Aug 20, 2026

Copy link
Copy Markdown
Contributor

Previously, the $self variable was declared so early that pad.c thought it was in an outer scope, and thus didn't warn of shadowing. By waiting until after the remember grammar token in perl.y we can ensure that the shadow warning still happens for duplicate declarations.

Fixes #24610

@leonerd leonerd added the class Issues related to 'class' keyword or __CLASS__ label Aug 20, 2026
Comment thread class.c

assert(cv == PL_compcv);
assert(HvSTASH_IS_CLASS(PL_curstash));

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need a PERL_UNUSED_ARG(cv);, since cv is only used in debug builds.

class.c:984:38: warning: unused parameter ‘cv’ [-Wunused-parameter]
  984 | Perl_class_declare_padvars(pTHX_ CV *cv)
      |                                  ~~~~^~

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ahyes, I keep forgetting about those ones.
Fixed.

@tonycoz

tonycoz commented Aug 24, 2026

Copy link
Copy Markdown
Contributor

Looks good otherwise.

Previously, the `$self` variable was declared so early that pad.c
thought it was in an outer scope, and thus didn't warn of shadowing. By
waiting until after the `remember` grammar token in `perl.y` we can
ensure that the shadow warning still happens for duplicate declarations.

Fixes Perl#24610
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

class Issues related to 'class' keyword or __CLASS__ hasConflicts

Projects

None yet

Development

Successfully merging this pull request may close these issues.

method from feature 'class' does not warn of shadowed $self variable

2 participants