Mailing List Archive

Make => on assignment a syntax error?
Hi all,

Someone recently complained about trying to debug something like this[1]:

$ perl -Mstrict -Mwarnings -E 'my $foo => 42; say $foo;'
Useless use of a constant (42) in void context at -e line 1.
Use of uninitialized value $foo in say at -e line 1.

If you're working with a codebase that doesn't have warnings, you won't
even get those warnings. You'll just get a silent, and very hard to track
down error.

When you're both declaring a variable and assigning to it, can we make
using => instead of = a syntax error? I've been bitten by this a few times
and the Useless use of a constant warning can get lost in a sea of stack
traces.

Best,
Ovid

1. https://github.polettix.it/ETOOBUSY/2023/05/16/syntax-checking/
Re: Make => on assignment a syntax error? [ In reply to ]
On Wed, May 17, 2023 at 8:50?AM Ovid <curtis.poe@gmail.com> wrote:

> Hi all,
>
> Someone recently complained about trying to debug something like this[1]:
>
> $ perl -Mstrict -Mwarnings -E 'my $foo => 42; say $foo;'
> Useless use of a constant (42) in void context at -e line 1.
> Use of uninitialized value $foo in say at -e line 1.
>
> If you're working with a codebase that doesn't have warnings, you won't
> even get those warnings. You'll just get a silent, and very hard to track
> down error.
>
> When you're both declaring a variable and assigning to it, can we make
> using => instead of = a syntax error? I've been bitten by this a few
> times and the Useless use of a constant warning can get lost in a sea of
> stack traces.
>

I understand the sentiment, but there is no assignment there. I'm not sure
how you would distinguish this case from `foo(my $bar => 'args')` which is
a perfectly valid construct though more commonly used with the skinnier
comma.

-Dan
Re: Make => on assignment a syntax error? [ In reply to ]
On Wed, May 17, 2023 at 8:06?PM Dan Book <grinnz@gmail.com> wrote:


> I understand the sentiment, but there is no assignment there. I'm not sure
> how you would distinguish this case from `foo(my $bar => 'args')` which is
> a perfectly valid construct though more commonly used with the skinnier
> comma.
>

That's an odd case. I've not seen it before. In any case, it's not in void
context, so perhaps that would distinguish the common problem?

I know my ask could be a longshot, but it's an annoyance I would love to
see go away :)

Best,
Ovid