Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

error message when declaring variables without a space between “my” and parens (my($test);) #5219

Open
p6rt opened this issue Apr 7, 2016 · 2 comments
Labels
LTA Less Than Awesome; typically an error message that could be better

Comments

@p6rt
Copy link

p6rt commented Apr 7, 2016

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

Searchable as RT127856$

@p6rt
Copy link
Author

p6rt commented Apr 7, 2016

From @AlexDaniel

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.

@p6rt
Copy link
Author

p6rt commented Oct 8, 2017

From @AlexDaniel

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​:

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.

@p6rt p6rt added the LTA Less Than Awesome; typically an error message that could be better label Jan 5, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
LTA Less Than Awesome; typically an error message that could be better
Projects
None yet
Development

No branches or pull requests

1 participant