{ ## closure for sub do_scan_sub
+ my %warn_if_lexical;
+
+ BEGIN {
+
+ # lexical subs with these names can cause parsing errors in this version
+ my @q = qw( m q qq qr qw qx s tr y );
+ @{warn_if_lexical}{@q} = (1) x scalar(@q);
+ }
+
# saved package and subnames in case prototype is on separate line
my ( $package_saved, $subname_saved );
my $is_lexical_sub =
$last_nonblank_type eq 'k' && $last_nonblank_token eq 'my';
if ( $is_lexical_sub && $1 ) {
- warning(
- "'my' sub $subname cannot be in package '$1'\n"
- );
+ warning("'my' sub $subname cannot be in package '$1'\n");
$is_lexical_sub = 0;
}
$current_sequence_number[BRACE][ $current_depth[BRACE] ];
$seqno = 1 unless ( defined($seqno) );
$package = $seqno;
+ if ( $warn_if_lexical{$subname} ) {
+ warning(
+"'my' sub '$subname' matches a builtin name and may not be handled correctly in this perltidy version.\n"
+ );
+ }
}
else {
$package = ( defined($1) && $1 ) ? $1 : $current_package;
# Check for multiple definitions of a sub, but
# it is ok to have multiple sub BEGIN, etc,
# so we do not complain if name is all caps
- if ( $saw_function_definition{$package}{$subname}
+ if ( $saw_function_definition{$subname}{$package}
&& $subname !~ /^[A-Z]+$/ )
{
- my $lno = $saw_function_definition{$package}{$subname};
+ my $lno = $saw_function_definition{$subname}{$package};
if ( $package =~ /^\d/ ) {
warning(
"already saw definition of lexical 'sub $subname' at line $lno\n"
);
}
}
- $saw_function_definition{$package}{$subname} =
+ $saw_function_definition{$subname}{$package} =
$tokenizer_self->[_last_line_number_];
}
}
=over 4
+=item B<Add warning when lexical sub names match some builtins>
+
+This update adds a warning when lexical subs have names which match some builtin
+names which will almost certainly cause a parsing error in the current version
+of perltidy. For example, the following program is valid and will run, but
+perltidy will produce an error.
+
+ use feature qw(lexical_subs);
+ use warnings; no warnings "experimental::lexical_subs";
+ {
+ my sub y { print "Hello from y: $_[0]\n"; }
+ y(1);
+ }
+
+6 Jun 2021.
+
=item B<Minor cleanups>
This update fixes a case of formatting instability recently found with random testing.
This fixes case b1139.
-5 Jun 2021.
-
+5 Jun 2021, b8527ab.
=item B<Revised data structures for welding>
simpler but more general structures. This cleans up the code and will
simplify future coding. No formatting changes should occur with this update.
-4 Jun 2021.
+4 Jun 2021, 4a886c8.
=item B<improved treatment of lexical subs>