Open dbh1997 opened 8 years ago
That goto inside the switch statement looks suspicious, I'm not sure it would even compile. Not sure what happened to all the cases in the switch statement - I don't run any code to prune cases...
Here’s a reproducible C# example that’s pared way back. Not sure it’s the minimum case, but probably small enough for what you need. In any event, you MUST turn the optimize flag on in project settings for this to reproduce, otherwise it works fine.
Should print true, but prints false.
enum TestSwitchEnum
{
A,
B,
C,
D,
E,
F,
G,
G2,
H = 350,
I = 351,
}
public static void SwitchDefect_899()
{
TestSwitch(TestSwitchEnum.C);
}
private static void TestSwitch(TestSwitchEnum e)
{
bool ok = true;
switch (e)
{
case TestSwitchEnum.B:
case TestSwitchEnum.C:
case TestSwitchEnum.E:
case TestSwitchEnum.F:
case TestSwitchEnum.G:
break;
default:
ok = false;
break;
}
Console.WriteLine(ok);
}
Join us for Xactware User Conference 2016 on Feb. 9-10 in Salt Lake City. Stay February 11 for an extra day of free training. Visit xactwareuserconference.com for more information.
This email is intended solely for the recipient. It may contain privileged, proprietary or confidential information or material. If you are not the intended recipient, please delete this email and any attachments and notify the sender of the error.
The opt flag is an important detail, thanks for calling it out. Does the large one fail without the opt flag?
It works fine with the flag off as well.
From: Katelyn Gadd [mailto:notifications@github.com] Sent: Thursday, November 05, 2015 12:35 PM To: sq/JSIL Cc: Harris, Dave Subject: Re: [JSIL] Section of switch statement is excluded from translation (#899)
The opt flag is an important detail, thanks for calling it out. Does the large one fail without the opt flag?
— Reply to this email directly or view it on GitHubhttps://github.com/sq/JSIL/issues/899#issuecomment-154166840.
Join us for Xactware User Conference 2016 on Feb. 9-10 in Salt Lake City. Stay February 11 for an extra day of free training. Visit xactwareuserconference.com for more information.
This email is intended solely for the recipient. It may contain privileged, proprietary or confidential information or material. If you are not the intended recipient, please delete this email and any attachments and notify the sender of the error.
C# function
Function as shown in ILSPY. It added the outer switch statement, probably these two values were disjointed enough in value from the others to warrant this optimization.
Translation to JS
Most of the cases are excluded. Perhaps the optimizer got a little aggressive and thought it was unnecessary pass through code. If it weren't for the "default" switch statement, then this would absolutely make for a good optimization.
The fix was easy enough. Change the first set of case statement to return true, and return false at the bottom of the function. No reason to bother with temp variable.
Translation after change: