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/warning for unary -,+ in void context? #33859

Open
JeffBezanson opened this issue Nov 15, 2019 · 4 comments
Open

error/warning for unary -,+ in void context? #33859

JeffBezanson opened this issue Nov 15, 2019 · 4 comments
Labels
speculative Whether the change will be implemented is speculative

Comments

@JeffBezanson
Copy link
Sponsor Member

I recently saw a case where code like this:

x = f(z) + g(z) - h(z)
y = ...

was reformatted to:

x = f(z) + g(z)
         - h(z)
y = ...

Of course, that silently changes the x value computed, and the value of - h(z) is just ignored. While rare, it's totally understandable how a change like this could be made accidentally. It makes me wonder if we should actually make this an error. Very few cases are affected; this can basically only happen with - and +, and it's hard to see why you would want to call those with one argument in void context.

@JeffBezanson JeffBezanson added the speculative Whether the change will be implemented is speculative label Nov 15, 2019
@stevengj
Copy link
Member

I've defined +(::String) to file an issue for the most recently loaded package, so adding a warning here would break my workflow.

@StefanKarpinski
Copy link
Sponsor Member

StefanKarpinski commented Nov 26, 2019

I realize that's not a serious comment, but that wouldn't be in void context, so this change actually wouldn't break your workflow 😁

@stevengj
Copy link
Member

Actually it would be in a void context—the point of the joke was that this would only affect someone who has perversely defined a unwary +/- method with a side effect.

@DanielDoehring
Copy link

DanielDoehring commented Oct 7, 2022

I recently lost half a day in debugging a statement of the form

a = b 
   + c

which is not the desired
a = b + c

I can understand that a leading - is taken without complaints, but what about throwing at least a warning if there are statements beginning with an + ?
In my opinion, there are extremely few cases (not talking about the representation of internal functions like sum for one element) where a user would use + with only one operator.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
speculative Whether the change will be implemented is speculative
Projects
None yet
Development

No branches or pull requests

4 participants