Integrated: 8263642: javac emits duplicate checkcast for first bound of intersection type in cast

Guoxiong Li gli at openjdk.java.net
Wed Jun 2 17:20:39 UTC 2021


On Thu, 8 Apr 2021 16:29:04 GMT, Guoxiong Li <gli at openjdk.org> wrote:

> Hi all,
> 
> Before the phase `desugar`, the demo `(C1 & I1) o` has **one** type-cast sub-tree, `JCTypeIntersection C1&I1`, at the syntax tree. After the phase `desugar`, the `(C1 & I1) o` becomes **three** type-cast sub-trees: `JCTypeIntersection C1&I1`, `I1`, `C1`. So at phase `Gen`, `javac` generates **three** `checkcast` according to the **three** type-cast sub-trees which causes this bug.
> 
> This patch doesn't generate `checkcast` when the type is `JCTypeIntersection` so that the problem can be solved. And a corresponding test case is added.
> 
> Another way to solve this issue is that the `TransTypes` of  the `desugar` should be modified and **two** type-cast sub-trees should be generated instead of **three**. But this way may change more code than my original patch and may cause other regression.
> 
> Thank you for taking the time to review.
> 
> Best Regards.
> --Guoxiong

This pull request has now been integrated.

Changeset: b7ac705d
Author:    Guoxiong Li <gli at openjdk.org>
Committer: Vicente Romero <vromero at openjdk.org>
URL:       https://git.openjdk.java.net/jdk/commit/b7ac705dd625c5fb2df714e2faec8d0ffac7301a
Stats:     110 lines in 2 files changed: 108 ins; 0 del; 2 mod

8263642: javac emits duplicate checkcast for first bound of intersection type in cast

Reviewed-by: vromero

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

PR: https://git.openjdk.java.net/jdk/pull/3399


More information about the compiler-dev mailing list