RFR: 8291657: Javac assertion when compiling a method call with switch expression as argument
Jan Lahoda
jlahoda at openjdk.org
Tue Sep 13 13:09:50 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?
Seems reasonable to me.
-------------
Marked as reviewed by jlahoda (Reviewer).
PR: https://git.openjdk.org/jdk/pull/10232
More information about the compiler-dev
mailing list