Page MenuHomeFeedback Tracker

Enscript parser bugs with switch statement
New, NormalPublic

Description

In switch statements, you can terminate a break statement with a colon.

switch (2) {
  case 0: {
    break: // notice the colon, an error should be thrown here and semicolon should be used.
  }
}

There is only one instance of this inside the AR code, Scripts/Game/Entities/SCR_TestRaycaster.c line 92, column 14.

You can put any statement within the switch block.

switch (2) {
	int a = 1337;
	if (true) {
		Print("inside switch line 9");
		Print(a);
		break; // this break is required, but the parser seems to not realise that this is not a switch case, if there is no break, "Switch: fallthrough cases can't have a body", that error message is also wrong, this is not even a case, we're inside an if statement which is at the toplevel of the switch block.
	}
	case 2: {
		Print("matched");
		break;
	}
}

You can nest switch cases inside each other.

switch (1) {
	case 0: {
		Print(0);
		break; // this break is required, otherwise you get "Switch: fallthrough cases can't have a body".
		case 1: { // because we are nesting switch cases, the below essentially allows us to fallthrough cases with bodies (no break is required anymore).
			Print(1); // this is most likely because nesting of switch cases is not expected, thus the check is only made for the toplevel switch case (if it breaks or not).
			case 2: {
				Print(2);
			}
		}
	}
}

The output for the above code is 1 and 2 (match 1, fallthrough into 2).

Details

Severity
None
Resolution
Open
Reproducibility
Always
Operating System
Windows 10 x64
Category
General

Event Timeline

sharp1337 created this task.Nov 7 2022, 4:17 PM
sharp1337 updated the task description. (Show Details)