Raku / old-issue-tracker

Tickets from RT
https://github.com/Raku/old-issue-tracker/issues
2 stars 1 forks source link

error message when a semicolon is missing before a while loop (my $x = 5 while True {}) #5852

Open p6rt opened 7 years ago

p6rt commented 7 years ago

Migrated from rt.perl.org#130251 (status was 'new')

Searchable as RT130251$

p6rt commented 7 years ago

From @AlexDaniel

Code​: my $x = 5

while True { }

Result​: ===SORRY!=== Error while compiling -e Unexpected block in infix position (missing statement control word before the expression?) at -e​:3 ------> while True⏏ {   expecting any of​:   infix   infix stopper

So it is parsed as a statement modifier, that's fine, but the problem is that the error message is way off whet it trips over a block. “Did you forget a semicolon on the previous line?” would be a good addition, but we'd need some heuristic for that.

p6rt commented 7 years ago

From mefzz@cpan.org

On Sat, 03 Dec 2016 07​:51​:07 -0800, alex.jakimenko@​gmail.com wrote​:

Code​: my $x = 5

while True { }

Result​: ===SORRY!=== Error while compiling -e Unexpected block in infix position (missing statement control word before the expression?) at -e​:3 ------> while True⏏ { expecting any of​: infix infix stopper

So it is parsed as a statement modifier, that's fine, but the problem is that the error message is way off whet it trips over a block. “Did you forget a semicolon on the previous line?” would be a good addition, but we'd need some heuristic for that.

This is a good suggestion, I would say. The error information is a bit complex for a very simple semicolon missing. -- 'There is only two types of testing. One, a testing by the developer. Two, a testing by the end user.

uchuugaka commented 4 years ago

Well, I have hit the same thing forgetting a semicolon with the first example code in Morris Lentz' book, Raku Fundamentals : A Primer with Examples, Projects, and Case Studies, and this is an especially devilish error if one is also often working with languages that do not require semicolons to end statements.

I had

# file sudoku.p6
use v6.d;

my $sudoku = '000000075000080094000500600010000200000900057006003040001000023080000006063240000'
for 0..8 -> $line-number {
  say substr $sudoku, $line-number * 9, 9;
}

but should have had

# file sudoku.p6
use v6.d;

my $sudoku = '000000075000080094000500600010000200000900057006003040001000023080000006063240000';
for 0..8 -> $line-number {
  say substr $sudoku, $line-number * 9, 9;
}

And yeah, it returned

% raku sudoku.p6 
===SORRY!=== Error while compiling /Users/john.joyce/Documents/Programming/Perl 6/Raku/sudoku.p6
Unexpected block in infix position (missing statement control word before the expression?)
at ~/path/to/sudoku.p6:5
------> for 0..8⏏ -> $line-number {
    expecting any of:
        infix
        infix stopper
uchuugaka commented 4 years ago

Fits the very definition of LTA!!!