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

Aggelos Biboudis abimpoudis at openjdk.org
Wed Sep 14 06:51:11 UTC 2022


On Fri, 9 Sep 2022 15:04:13 GMT, Aggelos Biboudis <abimpoudis at openjdk.org> wrote:

> 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?

This pull request has now been integrated.

Changeset: 1169a159
Author:    Aggelos Biboudis <abimpoudis at openjdk.org>
Committer: Jan Lahoda <jlahoda at openjdk.org>
URL:       https://git.openjdk.org/jdk/commit/1169a1593660242375400e9d6b9ca11a872cdf02
Stats:     46 lines in 2 files changed: 45 ins; 0 del; 1 mod

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

Reviewed-by: jlahoda

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

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


More information about the compiler-dev mailing list