RFR: 8291657: Javac assertion when compiling a method call with switch expression as argument

Aggelos Biboudis abimpoudis at openjdk.org
Fri Sep 9 15:11:14 UTC 2022


The following crashes on `Gen` when emitting code at `visitYield`.

        return (B) switch (o) {
            default -> new A();
        };

Why? Because the `yield` is retyped in `TransTypes` to `(B) new A()` and during `visitYield` in `Gen.java`, there is a check that essentially says: check the last type and assert if its a super-type of the current type.

That retype in `TransTypes` is exercised in one test regarding intersection types.

Now, if I write a redundant cast:

        return (B) (A) switch (o) {
            default -> new A();
        };

it works. because the `Yield` is not retyped. This PR translates the cases with the correct prototype (of the type of the switch itself -- `A` in the aforementioned examples).

WDYT?

-------------

Commit messages:
 - 8291657: Javac assertion when compiling a method call with switch expression as argument

Changes: https://git.openjdk.org/jdk/pull/10232/files
 Webrev: https://webrevs.openjdk.org/?repo=jdk&pr=10232&range=00
  Issue: https://bugs.openjdk.org/browse/JDK-8291657
  Stats: 46 lines in 2 files changed: 45 ins; 0 del; 1 mod
  Patch: https://git.openjdk.org/jdk/pull/10232.diff
  Fetch: git fetch https://git.openjdk.org/jdk pull/10232/head:pull/10232

PR: https://git.openjdk.org/jdk/pull/10232


More information about the compiler-dev mailing list