Fixed translator's Java sources list in public build.#2618
Merged
copybara-service[bot] merged 1 commit intogoogle:masterfrom Nov 6, 2025
Merged
Fixed translator's Java sources list in public build.#2618copybara-service[bot] merged 1 commit intogoogle:masterfrom
copybara-service[bot] merged 1 commit intogoogle:masterfrom
Conversation
tomball
referenced
this pull request
Nov 6, 2025
Switch expressions are rewritten as switch statements in a expression block, e.g:
```
a + switch (someEnum) {
case VALUE1:
case VALUE2:
yield 2;
case LASTVALUE:
yield 3;
}
```
is rewritten to:
```
a + ^{ switch (someEnum) {
case VALUE1:
case VALUE2:
return 2;
case LASTVALUE:
return 3;
default:
__builtin_unreachable();
}}()
```
and switches with patterns or guards are rewritten into if nests that set a selector variable and the switch is converted to use that variable, e.g:
```
switch (someEnum) {
case String s -> s.length();
case Integer i -> i;
default -> 0;
}
```
is translated as if it was written as:
```
int selector = 0;
if (someEnum instanceof String s) {
selector = 1;
} else if (someEnum instanceof Integer i) {
selector = 2;
}
switch (selector) {
case 1 -> s.length();
case 2 -> i;
default -> 0;
}
```
Note that the pattern variables will be extracted out and will have the proper value in the places where they can be accessed.
PiperOrigin-RevId: 828453235
Collaborator
|
Ahh. I didn't see that. I also renamed the corresponding test. |
rluble
approved these changes
Nov 6, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
translate/SwitchConstructRewriter.javareplacedtranslate/SwitchCaseRewriter.java, so this updates the Make build's sources list.