Issue with enhanced switch statements in GWT 2.12.1

113 views
Skip to first unread message

Craig Mitchell

unread,
Nov 21, 2024, 3:28:51 AM11/21/24
to GWT Users

> Switch statements can correctly compile without being contained in braces

For me, they compile, but they don't work.  Eg.  This code:

GWT.log("Test 1 - Start");
switch (1) {
  case 1 -> {
    GWT.log("Test 1 - 1");
  }
  case 2 -> {
    GWT.log("Test 1 - 2");
  }
  case 3 -> {
    GWT.log("Test 1 - 3");
  }
}
GWT.log("Test 1 - Done");

GWT.log("Test 2 - Start");
switch (1) {
  case 1 -> GWT.log("Test 2 - 1");
  case 2 -> GWT.log("Test 2 - 2");
  case 3 -> GWT.log("Test 2 - 3");
}
GWT.log("Test 2 - Done");

Will never get to the last "Test 2 - Done" line.  The output will be:
Test 1 - Start
Test 1 - 1
Test 1 - Done
Test 2 - Start
Test 2 - 1

Is this a known issue?

Thanks.

Vassilis Virvilis

unread,
Nov 21, 2024, 3:39:07 AM11/21/24
to google-we...@googlegroups.com
I must be low on caffeine because I can't see the problem.

Is the problem that it doesn't print:
Test 2 - Done
at the end?

--
You received this message because you are subscribed to the Google Groups "GWT Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-web-tool...@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/google-web-toolkit/d0b4fe79-0571-481a-bf4f-c8ccda40e486n%40googlegroups.com.


--
Vassilis Virvilis

Thomas Broyer

unread,
Nov 21, 2024, 4:04:39 AM11/21/24
to GWT Users
Could be related to https://github.com/gwtproject/gwt/issues/10044

Fwiw, the issue fixed in 2.12.1 was not about the "case x -> foo" vs "case x -> { foo }" but about enclosing the whole switch inside a block.

Craig Mitchell

unread,
Nov 21, 2024, 4:37:31 AM11/21/24
to GWT Users
Thanks Thomas.  Yes, that's the same issue.  I've now commented on it.  Cheers.

Vassilis Virvilis

unread,
Nov 21, 2024, 5:17:32 AM11/21/24
to google-we...@googlegroups.com
lack of caffeine indeed.

Somehow the sentence that was explaining the problem disappeared for me between scrolls..

Sorry
--
Vassilis Virvilis

Colin Alworth

unread,
Nov 21, 2024, 4:18:47 PM11/21/24
to GWT Users
Thanks, this was filed at https://github.com/gwtproject/gwt/issues/10044. The issue is that we misunderstood how the JDT AST handled this case (assumed it was a block ending in a break, rather than a yield with a void expression, which isn't legal in Java), and the tests didn't check for flow in the method after the switch was finished (it is a little awkward to put an assert after a code block and validate not just that it passes but was run at all. We'll get this fixed soon, with better tests as well.
Reply all
Reply to author
Forward
0 new messages