Julia: error/warning for unary -,+ in void context?

Created on 15 Nov 2019  路  3Comments  路  Source: JuliaLang/julia

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.

speculative

Most helpful comment

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

All 3 comments

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

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 馃榿

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

Was this page helpful?
0 / 5 - 0 ratings

Related issues

JeffBezanson picture JeffBezanson  路  167Comments

juliohm picture juliohm  路  146Comments

kmsquire picture kmsquire  路  283Comments

stevengj picture stevengj  路  174Comments

StefanKarpinski picture StefanKarpinski  路  141Comments