Skip Menu |
Report information
Id: 127856
Status: new
Priority: 0/
Queue: perl6

Owner: Nobody
Requestors: alex.jakimenko [at] gmail.com
Cc:
AdminCc:

Severity: (no value)
Tag: (no value)
Platform: (no value)
Patch Status: (no value)
VM: (no value)



Subject: LTA error message when declaring variables without a space between “my” and parens (my($test);)
Download (untitled) / with headers
text/plain 1.1k
Code: my($test) = 42 Result: ===SORRY!=== Error while compiling -e Variable '$test' is not declared at -e:1 ------> my(⏏$test) = 42 Sure enough $test is not declared, I am trying to declare it! This error message is especially sad considering that this is allowed: Code: my$test = 42; Result: (no output, everything works correctly) And of course, it is always interesting to see real life examples of people struggling with an LTA error: http://irclog.perlgeek.de/perl6/2016-04-07#i_12303463 The reason why my() is not allowed is probably exactly the same as the reason why we don't have if(), but at least in the latter case provide a meaningful error message. Let's take a look at what happens if you try to use if(): Code: if(1) {} Result: ===SORRY!=== Word 'if' interpreted as 'if()' function call; please use whitespace instead of parens at -e:1 ------> if⏏(1) {} Unexpected block in infix position (two terms in a row) at -e:1 Well, we should not say that the user should use whitespace instead of parens (maybe he/she is trying to declare multiple variables), but we should definitely say how it is interpreted and that a space between the parens and “my” will solve the problem.
Basically, this would need to throw X::Syntax::KeywordAsFunction, but it blows up when trying to look up $test so that's rather unfortunate. Pretty sure we can do something about it but maybe it's not a one-line fix.

On 2016-04-07 16:29:37, alex.jakimenko@gmail.com wrote:
Show quoted text
> Code:
> my($test) = 42
>
> Result:
> ===SORRY!=== Error while compiling -e
> Variable '$test' is not declared
> at -e:1
> ------> my(⏏$test) = 42
>
>
> Sure enough $test is not declared, I am trying to declare it!
>
> This error message is especially sad considering that this is allowed:
>
> Code:
> my$test = 42;
>
> Result:
> (no output, everything works correctly)
>
>
> And of course, it is always interesting to see real life examples of
> people struggling with an LTA error:
> http://irclog.perlgeek.de/perl6/2016-04-07#i_12303463
>
> The reason why my() is not allowed is probably exactly the same as the
> reason why we don't have if(), but at least in the latter case provide
> a meaningful error message. Let's take a look at what happens if you
> try to use if():
>
> Code:
> if(1) {}
>
> Result:
> ===SORRY!===
> Word 'if' interpreted as 'if()' function call; please use whitespace
> instead of parens
> at -e:1
> ------> if⏏(1) {}
> Unexpected block in infix position (two terms in a row)
> at -e:1
>
>
> Well, we should not say that the user should use whitespace instead of
> parens (maybe he/she is trying to declare multiple variables), but we
> should definitely say how it is interpreted and that a space between
> the parens and “my” will solve the problem.




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

For issues related to this RT instance (aka "perlbug"), please contact perlbug-admin at perl.org