Skip to content

Fixed translator's Java sources list in public build.#2618

Merged
copybara-service[bot] merged 1 commit intogoogle:masterfrom
tomball:master
Nov 6, 2025
Merged

Fixed translator's Java sources list in public build.#2618
copybara-service[bot] merged 1 commit intogoogle:masterfrom
tomball:master

Conversation

@tomball
Copy link
Copy Markdown
Collaborator

@tomball tomball commented Nov 6, 2025

translate/SwitchConstructRewriter.java replaced translate/SwitchCaseRewriter.java, so this updates the Make build's sources list.

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
@rluble
Copy link
Copy Markdown
Collaborator

rluble commented Nov 6, 2025

Ahh. I didn't see that. I also renamed the corresponding test.

@copybara-service copybara-service Bot merged commit 58f6989 into google:master Nov 6, 2025
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants