You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
**GWT version: 2.12.1
**Browser (with version): all
**Operating System: all
Description
Single assignments as case statements should behave the same whether within {} or not.
Instead, with {} around them, these assignments generate correct JS, but if not surrounded with {}, the generated case statements have superfluous return statements that lead to function termination
Steps to reproduce
public void onModuleLoad() {
String s = "a";
switch (s) {
case "a" -> result = 1;
default -> result = 2;
}
Window.alert("result:" + result); // is never reached
}
generated JS:
_.onModuleLoad_0_g$ = function z_g$(){
var s_0_g$;
s_0_g$ = 'a';
switch (s_0_g$) {
case 'a':
return this.result_1_g$ = 1;
default:return this.result_1_g$ = 2;
}
X9c_g$('result:' + this.result_1_g$);
}
;
Known workarounds
Put {} around case-statements
public void onModuleLoad() {
String s = "a";
switch (s) {
case "a" -> { result = 1; }
default -> { result = 2; }
}
Window.alert("result:" + result); // is reached
}
JDT generates a yield for arrow cases if the arrow points at a
expression, even though the expression cannot be returned. Synthesize a
block wrapping that expression as a statement, and add a break to the
end of it.
Fixesgwtproject#10044
There is a maven snapshot for this with version gwt-2.13.0-10044-case-yield-test-SNAPSHOT at https://repo.vertispan.com/gwt-snapshot/ also available for testing.
**GWT version: 2.12.1
**Browser (with version): all
**Operating System: all
Description
Single assignments as case statements should behave the same whether within {} or not.
Instead, with {} around them, these assignments generate correct JS, but if not surrounded with {}, the generated case statements have superfluous return statements that lead to function termination
Steps to reproduce
generated JS:
Known workarounds
Put {} around case-statements
generated JS:
The text was updated successfully, but these errors were encountered: