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
ID:2130824
Aug 12 2016, 11:36 am
|
|||||||||||||
Resolved
| |||||||||||||
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. |
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. |
In other languages, the following kind of construct is quite useful and common:
However, clang (C compiler) exhibits the following behavior: