develooper Front page | perl.perl5.porters | Postings from October 2014

[perl #122966] [PATCH] bogus fatal warnings can hide syntax errors

Thread Previous | Thread Next
From:
Father Chrysostomos via RT
Date:
October 13, 2014 13:12
Subject:
[perl #122966] [PATCH] bogus fatal warnings can hide syntax errors
Message ID:
rt-4.0.18-26868-1413205924-941.122966-15-0@perl.org
On Mon Oct 13 01:35:03 2014, mauke- wrote:
> The Problem
> -----------
> 
> Consider this code:
> 
> #!perl
> use strict;
> use warnings;
> 
> if (1 {
>     my $wtf = 42;
>     print "$wtf\n";
> }
> __END__
> 
> If you run that, you get:
> 
> "my" variable $wtf masks earlier declaration in same statement at
> foo.pl line 7.
> syntax error at foo.pl line 5, near "1 {"
> syntax error at foo.pl line 8, near "}"
> Execution of foo.pl aborted due to compilation errors.
> 
> I.e. there's a bogus warning on line 7, then the actual error on line
> 5.
> 
> Now the same code with fatal warnings:
> 
> #!perl
> use strict;
> use warnings FATAL => 'all';
> 
> if (1 {
>     my $wtf = 42;
>     print "$wtf\n";
> }
> __END__
> 
> This time the output is just:
> 
> "my" variable $wtf masks earlier declaration in same statement at
> bar.pl line 7.
> 
> The actual error is completely hidden because the bogus warning throws
> an exception and aborts everything.
> 
> 
> My Solution
> -----------
> 
> I've attached a patch that solves this problem by simply defatalizing
> warnings if we're currently parsing and there are pending parse
> errors. I think this is a good way to handle this situation because we
> don't know whether the warning we're about to emit is useful or caused
> by misinterpretation of the code after a syntax error. So we warn non-
> fatally because the pending parse errors will throw an exception later
> on anyway.
> 
> Thoughts?

Since the programmer has requested fatal warnings, why not send it to qerror instead of simply turning off the fatality?

-- 

Father Chrysostomos


---
via perlbug:  queue: perl5 status: new
https://rt.perl.org/Ticket/Display.html?id=122966

Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About