Skip Menu |
 

This queue is for tickets about the Perl-Tidy CPAN distribution.

Report information
The Basics
Id: 114909
Status: resolved
Priority: 0/
Queue: Perl-Tidy

People
Owner: Nobody in particular
Requestors: KENTNL [...] cpan.org
Cc:
AdminCc:

Bug Information
Severity: (no value)
Broken in: (no value)
Fixed in: (no value)



Subject: Anonymous subs with signatures and prototypes misparsed as broken ternaries

The following basic code works fine and does what you expect, and the "*" prototype is required to permit using STDIN as a bareword.

---
 

#!perl
use strict;
use warnings;

use experimental 'signatures';

sub reader ( $line_sep, $chomp ) {
    return sub ( $fh, $out ) : prototype(*$) {
        local $/ = $line_sep;
        my $content = <$fh>;
        return undef unless defined $content;
        chomp $content if $chomp;
        $$out .= $content;
        return 1;
    };
}

BEGIN {
    *get_line = reader( "\n", 1 );
}

while ( get_line( STDIN, \my $buf ) ) {
    print "Got: $buf\n";
}

---

 

However, Perltidy emits this:

---

Perltidy version is 20160302

There is no previous '?' to match a ':' on line 8
8: return sub ( $fh, $out ) : prototype(*$) {
----

.LOG attached.

 


 

Subject: x.pl.LOG
Download x.pl.LOG
text/plain 2.5k
perltidy version 20160302 log file on a linux system, OLD_PERL_VERSION=5.025001 Configuration and command line parameters for this run: -g To find error messages search for 'WARNING' with your editor Indentation will be with 4 spaces Line 1 implies starting-indentation-level = 0 The nesting depths in the table below are at the start of the lines. The indicated output line numbers are not always exact. ci = levels of continuation indentation; bk = 1 if in BLOCK, 0 if not. in:out indent c b nesting code + messages; (messages begin with >>>) lines levels i k (code begins with one '.' per indent level) ------ ----- - - -------- ------------------------------------------- L2:2 i0:0 0 1 use strict; L3:3 i0:0 0 1 use warnings; L5:5 i0:0 0 1 use experimental 'signatures'; L7:7 i0:0 0 1 sub reader( $line_sep, $chomp ) { ######################## WARNING ######################### There is no previous '?' to match a ':' on line 8 8: return sub ( $fh, $out ) : prototype(*$) { ^ ############################################################ L8:8 i0:1 0 1 { .return sub ( $fh, $out ) : prototy .... L8:8 i0:1 0 1 { >>>Start indentation disagreement: input=0; output=1 L9:9 i1:2 0 1 {{ ..local $/ = $line_sep; L10:10 i1:2 0 1 {{ ..my $content = <$fh>; L11:11 i1:2 0 1 {{ ..return undef unless defined $cont .... L12:12 i1:2 0 1 {{ ..chomp $content if $chomp; L13:13 i1:2 0 1 {{ ..$$out .= $content; L14:14 i1:2 0 1 {{ ..return 1; L15:15 i0:1 0 1 {{ .}; L16:16 i0:0 0 1 { } L16:16 i0:0 0 1 { >>>End indentation disagreement from input line 8 L18:18 i0:0 0 1 BEGIN { L19:19 i0:1 0 1 { .*get_line = reader("\n", 1 ); L19:19 i0:1 0 1 { >>>Start indentation disagreement: input=0; output=1 L20:20 i0:0 0 1 { } L20:20 i0:0 0 1 { >>>End indentation disagreement from input line 19 L22:22 i0:0 0 1 while( get_line( STDIN, \my $buf ) .... L23:23 i0:1 0 1 { .print "Got: $buf\n"; L23:23 i0:1 0 1 { >>>Start indentation disagreement: input=0; output=1 L24:24 i0:0 0 1 { } L24:24 i0:0 0 1 { >>>End indentation disagreement from input line 23 First indentation disagreement seen at input line 8 Last indentation disagreement seen at input line 23 Note: Indentation disagreement detection is not accurate for outdenting and -lp. No lines exceeded 80 characters Maximum output line length was 46 at line 8
This is fixed in version 20170521.


This service is sponsored and maintained by Best Practical Solutions and runs on Perl.org infrastructure.

Please report any issues with rt.cpan.org to rt-cpan-admin@bestpractical.com.