my ( $next_nonblank_token, $i_next ) =
find_next_nonblank_token( $i, $rtokens,
$max_token_index );
- if ( $next_nonblank_token ne ')' ) {
+
+ # Patch for c029: give up error check if
+ # a side comment follows
+ if ( $next_nonblank_token ne ')'
+ && $next_nonblank_token ne '#' )
+ {
my $hint;
error_if_expecting_OPERATOR('(');
# if -> points to a bare word, we must scan for an identifier,
# otherwise something like ->y would look like the y operator
+
+ # NOTE: this will currently allow things like
+ # '->@array' '->*VAR' '->%hash'
+ # to get parsed as identifiers, even though these are not currently
+ # allowed syntax. To catch syntax errors like this we could first
+ # check that the next character and skip this call if it is one of
+ # ' @ % * '. A disadvantage with doing this is that this would
+ # have to be fixed if the perltidy syntax is ever extended to make
+ # any of these valid. So for now this check is not done.
scan_identifier_fast();
},
$last_nonblank_container_type = $container_type;
$last_nonblank_type_sequence = $type_sequence;
$last_nonblank_i = $i_tok;
+
+ # Patch for c030: Fix things in case a '->' got separated from
+ # the subsequent identifier by a side comment. We need the
+ # last_nonblank_token to have a leading -> to avoid triggering
+ # an operator expected error message at the next '('. See also
+ # fix for git #63.
+ if ( $last_last_nonblank_token eq '->' ) {
+ if ( $last_nonblank_type eq 'w'
+ || $last_nonblank_type eq 'i'
+ && substr( $last_nonblank_token, 0, 1 ) eq '$' )
+ {
+ $last_nonblank_token = '->' . $last_nonblank_token;
+ $last_nonblank_type = 'i';
+ }
+ }
}
# store previous token type
@{op_expected_table}{@q} = (TERM) x scalar(@q);
# Always UNKNOWN following these types:
- @q = qw( w );
+ # Fix for c030: added '->' to this list
+ @q = qw( w -> );
@{op_expected_table}{@q} = (UNKNOWN) x scalar(@q);
# Always expecting OPERATOR ...
# 'n' and 'v' are currently excluded because they might be VERSION numbers
# 'i' is currently excluded because it might be a package
# 'q' is currently excluded because it might be a prototype
- @q = qw( -- C -> h R ++ ] Q <> ); ## n v q i );
+ # Fix for c030: removed '->' from this list:
+ @q = qw( -- C h R ++ ] Q <> ); ## n v q i );
push @q, ')';
@{op_expected_table}{@q} = (OPERATOR) x scalar(@q);
my ($rarg) = @_;
+ my $msg = "";
+
##############
# Table lookup
##############
# Many types are can be obtained by a table lookup given the previous type.
# This typically handles half or more of the calls.
my $op_expected = $op_expected_table{$last_nonblank_type};
- goto RETURN if ( defined($op_expected) );
+ if ( defined($op_expected) ) {
+ $msg = "Table lookup";
+ goto RETURN;
+ }
######################
# Handle special cases
DEBUG_OPERATOR_EXPECTED && do {
print STDOUT
-"OPERATOR_EXPECTED: returns $op_expected for last type $last_nonblank_type token $last_nonblank_token\n";
+"OPERATOR_EXPECTED: $msg: returns $op_expected for last type $last_nonblank_type token $last_nonblank_token\n";
};
return $op_expected;
=over 4
+=item B<Fix some incorrect error messages due to side comments>
+
+Testing with large numbers of side comments caused perltidy to produce some
+incorrect error messages. Two issues are fixed with this update. First, a side
+comment between a pointer '->' and the next identifier caused a message.
+Second, in some cases a comment after an opening paren could cause a message.
+The following snippet is an example.
+
+ $Msg#sc#
+ ->#sc#
+ $field#sc#
+ (#sc#
+ )#sc#
+ ;#sc#
+
+This update fixes cases c029 and c030.
+
+4 Jul 2021.
+
=item B<Fix undefined var ref involving --format-skipping>
Testing produced a situation in which version 20200625 could cause an undefined
This update fixes this problem.
-4 Jul 2021.
+4 Jul 2021, 82916fe.
=item B<Check for side comment within package statement>
;
This update fixes this.
-3 Jul 2021.
+3 Jul 2021, c00059a.
=item B<Fix problem with -comma-arrow-breakpoint=n flag>