ID:2130824
 
Resolved
Using = instead of == in a condition like if(), while(), or the middle of for() will now generate a warning on compilation. To avoid this warning in cases where this is desired, enclose the expression in extra parentheses.
BYOND Version:511.1352
Operating System:Windows 10 Home
Web Browser:Chrome 52.0.2743.116
Applies to:DM Language
Status: Resolved (511.1380)

This issue has been resolved.
Descriptive Problem Summary: Compiler isnt returning an error when you forget the second equal sign in an if statement. instead it just changes the variable your checking into the variable/value you were checking it with. If that was an intended change to the compiler it's really shit cause its a common mistake to forget the extra equal sign every now and then. also this wasnt fixed http://www.byond.com/forum/?post=2127876#comment20652696
I would personally argue that this may not be considered a full-bug, but rather a situation warranting a warning (at best) if possible.

In other languages, the following kind of construct is quite useful and common:

if((foo = bar()) != 0) {
// error
}


However, clang (C compiler) exhibits the following behavior:

if(x = 5) // warning: using the result of an assignment as a condition without parentheses [-Wparentheses]


if((x = 5)) // OK

Need a code sample here.
if(src.x=5) x changes to 5 and gives no error

edit: also im fine with a warning but it slipped through when i hosted a game because i didn't notice and caused a lot of headache
Oh. This indeed is not a bug, but a result of the new assignment chaining in 511. However I agree it would be ideal to have a warning on this. The trick is, I need some way of keeping track of the fact that the node was enclosed with parentheses, which the compiler doesn't currently do.
Argh, that warning is gonna be a pain to add. The nodes don't keep track of any special info like this, and there isn't any difference after parsing between (X) and X. I'm not sure I necessarily need to add any info to the nodes, or if I can handle this at an earlier stage with some kind of a flag.
Adding a warning to this would be annoying in cases where it's used legitimately.
In response to Mloc
Mloc wrote:
Adding a warning to this would be annoying in cases where it's used legitimately.

The idea isn't to add a warning because you want to make an assignment in an if() condition, it's to make sure you did it intentionally. It forces you to re-evaluate the statement, just in case, by enforcing an extra set of parentheses around it to make the warning go away.
Fair nuff, I missed that bit.
Lummox JR resolved issue with message:
Using = instead of == in a condition like if(), while(), or the middle of for() will now generate a warning on compilation. To avoid this warning in cases where this is desired, enclose the expression in extra parentheses.
Thanks for fixing this, I'm sure it could have caused more issues in the future.