RFR: 8263642: javac emits duplicate checkcast for first bound of intersection type in cast [v2]

Guoxiong Li gli at openjdk.java.net
Wed Jun 2 15:26:18 UTC 2021

> 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

Guoxiong Li has updated the pull request with a new target base due to a merge or a rebase. The incremental webrev excludes the unrelated changes brought in by the merge/rebase. The pull request contains four additional commits since the last revision:

 - Remove the duplicated typecast nodes in the AST instead of ignoring it
 - Check the type of the checkcast
 - Merge branch 'master' into JDK-8263642
 - 8263642: javac emits duplicate checkcast for first bound of intersection type in cast


  - all: https://git.openjdk.java.net/jdk/pull/3399/files
  - new: https://git.openjdk.java.net/jdk/pull/3399/files/f57b0c39..0806d1bd

 - full: https://webrevs.openjdk.java.net/?repo=jdk&pr=3399&range=01
 - incr: https://webrevs.openjdk.java.net/?repo=jdk&pr=3399&range=00-01

  Stats: 744161 lines in 10367 files changed: 120714 ins; 594378 del; 29069 mod
  Patch: https://git.openjdk.java.net/jdk/pull/3399.diff
  Fetch: git fetch https://git.openjdk.java.net/jdk pull/3399/head:pull/3399

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

More information about the compiler-dev mailing list