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

Feature request: generate warnings in void context in assignment statements #22261

Closed
EvanCarroll opened this issue Jun 4, 2024 · 3 comments
Closed

Comments

@EvanCarroll
Copy link

I wrote about this on StackOverflow when I observed it didn't generate a warning. This is the code,

$ perl -wE'sub foo {1}; sub bar {2}; sub baz {3}; my @foo = foo(), bar(), baz();

I found the underlying problem easily. But I think it may just be an oversight that it doesn't generate a warning. Seems pretty silly not to anyway.

https://stackoverflow.com/questions/78577874/why-are-functions-allowed-in-void-context-in-assignment-statements

@Grinnz
Copy link
Contributor

Grinnz commented Jun 4, 2024

The problem is this is not an "assignment statement", despite what it looks like to you knowing what your intent was; it is a statement with 3 expressions each executed in void context, one of which is an assignment. For instance, this is perfectly valid and extremely common, and the only difference is that the expressions are executed in list context: foo(my $x = 42, $y, $z)

@mauke
Copy link
Contributor

mauke commented Jun 4, 2024

What exactly are you requesting? Emit a warning whenever a function is called in void context?

@EvanCarroll
Copy link
Author

@Grinnz that makes sense. Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants