Statements placed before this() or super() call when using switch expression as argument
See original GitHub issueCFR version
0.150-SNAPSHOT (commit cf242d2)
Compiler
javac 14
Description
When using a switch expression (Java 14 feature) as argument for the call of this()
or super()
, statements are placed before the constructor call when decompiled which makes the code invalid.
Source:
class SwitchConstructorTest {
SwitchConstructorTest(int i) { }
SwitchConstructorTest(String s) {
// Also happens for super();
this(switch (s) {
case "a" -> 1;
default -> 2;
});
}
SwitchConstructorTest(Byte b) {
this(switch(b) {
default -> 1;
});
}
}
Decompiled output:
class SwitchConstructorTest {
SwitchConstructorTest(int n) {
}
SwitchConstructorTest(String string) {
// Invalid, no other statement must appear before call to this()
int n = switch (string) {
case "a" -> 1;
default -> 2;
};
this(n);
}
SwitchConstructorTest(Byte by) {
// Invalid, no other statement must appear before call to this()
switch (by) {
default:
}
this(1);
}
}
Issue Analytics
- State:
- Created 4 years ago
- Comments:5 (5 by maintainers)
Top Results From Across the Web
Switch Statement in C/C++ - GeeksforGeeks
The switch statement is a multiway branch statement. It provides an easy way to dispatch execution to different parts of code based on...
Read more >How to use Switch case Statement in Java with Example - Xperti
The statement or variable used as a switch expression must be a constant value otherwise it would not be valid. In the case...
Read more >Kotlin when: A switch with Superpowers - SuperKotlin
The when expression in Kotlin is much better than a switch statement: it can be used with arbitrary conditions, as a statement or...
Read more >Write Conditional Statement Using SWITCH in DAX and ...
Replacing the expression with TRUE, and the value of that with a conditional expression means that you get the same output, but this...
Read more >Expression inside switch case statement - Stack Overflow
The solution where the switch expression is set to true works not because true is a constant but because equality with the case...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
This was, frankly, horrible.
Tests https://github.com/leibnitz27/cfr_tests/commit/4754c97dc412cf035aebf73ea484bd0c94e44648
This was fixed for the first example where there is no fall-through to the default case by the fix for #129. However, the second example (fall-through to default case) still occurs, see also #133.