What will a newbie think of this misleading error message?
The error is rather straightforward to analyze. I'd be more concerned about the case with no error message.
sub function { return 8; }
$n = function + 4;
Do you really think a parser should throw an error if [...] it "guessed wrong" and needs to consider a different (valid) possibility?
I wonder if the tokenizer is capable of backtracking. Adding that capability would probably have a significant performance hit on the time it takes to compile Perl code.
Furthermore, I'm not convinced the problem can be fixed. Some cases cannot be fixed (like $n = function + 4;). Even if we were only fixing $n = function / 4;, the fix would necessarily introduce new problems. Consider:
$n = function /dir(\d+)\/;
Your "fix" would cause Perl to say
"Backslash found where operator expected"
instead of
"Search pattern not terminated"
That's worse.
Would you also like to fix the following, where it appears the "guess" resulted in a perfectly fine regexp?
sub function { '...' }
$x = function / 4;
$y = $n / 2;
There are major implications to trying to fix this last error.
|