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

[perl #123195] use warnings FATAL => 'all' causes wrong syntax error diagnostics

Thread Previous
From:
Father Chrysostomos via RT
Date:
November 13, 2014 12:41
Subject:
[perl #123195] use warnings FATAL => 'all' causes wrong syntax error diagnostics
Message ID:
rt-4.0.18-22696-1415882479-1084.123195-15-0@perl.org
On Wed Nov 12 23:45:15 2014, jim.avera@gmail.com wrote:
> 
> This is a bug report for perl from jim.avera@gmail.com,
> generated with the help of perlbug 1.40 running under perl 5.20.1.
> 
> 
> -----------------------------------------------------------------
> If a script using 'strict' also has "use warnings FATAL => 'all';"
> then referencing an undeclared $variable often results in a wildly
> inappropriate diagnostic from the parser (diagnosing correct code
> later in the program), and NO mention of the actual error.
> Usually the bogus diagnostic points to code far, far away from the
> mis-spelled variable reference, making it a pain to track down.
> 
> I never noticed this until now, and I recently upgraded from
> 5.18 to 5.20.1, so it *might* be a regression.
> 
> The following script produces _only_ the bogus diagnostic
> 
> Number found where operator expected at test.pl line 17, near "myfunc
> 1"
> 
> However, if the FATAL => 'all' is removed, then the reference to
> an undeclared variable is diagnosed correctly (in addition to the
> bogus error, which is not a problem because the actual error
> is also mentioned).
> 
> #!/usr/bin/perl
> use strict; use warnings;
> use warnings FATAL => 'all';  # comment this to allow correct
> diagnostic
> 
> $misspelled = @ARGV;
> 
> #.
> #.
> #.
> # thousands of lines of valid code here
> #.
> #.
> #.
> 
> sub myfunc(@) { }
> 
> sub bar { myfunc 1,2,3 ; };

$ pbpaste|perl5.8.7
Global symbol "$misspelled" requires explicit package name at - line 5.
Execution of - aborted due to compilation errors.
$ pbpaste|perl5.14.4
Global symbol "$misspelled" requires explicit package name at - line 5.
Execution of - aborted due to compilation errors.
$ pbpaste|perl5.18.1
Number found where operator expected at - line 17, near "myfunc 1"
$ pbpaste|perl5.20.1
Number found where operator expected at - line 17, near "myfunc 1"
$ pbpaste|perl5.21.5
Global symbol "$misspelled" requires explicit package name (did you forget to declare "my $misspelled"?) at - line 5.
	(Do you need to predeclare myfunc?)
syntax error at - line 17, near "myfunc 1"
Execution of - aborted due to compilation errors.

It looks as though we have already addressed this.  But I do wonder when ‘Number found’ disappeared.  I am also surprised that it changed in 5.18.

Thank you for the report.  This is an area that definitely needs more tests, so I’ll steal some of your code for that purpose. :-)

-- 

Father Chrysostomos


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

Thread Previous


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