ID:2406784
 
Resolved
BYOND Version:510
Operating System:Windows 10 Pro 64-bit
Web Browser:N/A
Applies to:DM Language
Status: Resolved

This issue has been resolved.
Descriptive Problem Summary:
I found this code:
switch(icon_state)
if("ia_jacket_open")
src.icon_state = "ia_jacket"
to_chat(usr, "You button up the jacket.")
if("ia_jacket")
src.icon_state = "ia_jacket_open"
to_chat(usr, "You unbutton the jacket.")
else
to_chat(usr, "You attempt to button-up the velcro on your [src], before promptly realising how retarded you are.")
return
usr.update_inv_wear_suit()


usr.update_inv_wear_suit()

never gets executed, because it's indented under the switch.
The fix is to de-dent once.

Executing the code even if indented incorrectly would be better than this, but the ideal result would be the failing the compilation entirely, because this is non-sense.

Here is a minimal version to reproduce the issue:
world/New()
switch(1)
if(1)
world.log << 1
if(2)
world.log << 2
else
world.log << 3
world.log << 4


The above only outputs "1".

Expected Results:
Compile error.

Actual Results:
Code silently ignored.

Does the problem occur:
It seems to happen when you have an else statement in the switch.

When does the problem NOT occur?
Switch statements without else statements properly fail to compile.
world/New()
switch(1)
if(1)
world.log << 1
if(2)
world.log << 2
world.log << 4

will fail with
test6.dm:7:error: <<: expected "if" or "else"


Did the problem NOT occur in any earlier versions? If so, what was the last version that worked? Tested on 512.1453 and 510.1347 on Windows 10 x64 Pro.

I see why this happens. Should be fixable pretty easily, although obviously it's not high priority.

What's going on here is a somewhat oversimplified loop that's going through nodes in pairs, with the assumption that all the if cases are followed by an else (at most). An if node has the if() condition as its child and the code block underneath it comes in the following node (at least in a switch it does), whereas an else node has the code block as its children. So because nodes are processed two at a time, when you have an else the node after it gets skipped.
Lummox JR resolved issue