RFR: 8348906: InstanceOfTree#getType doesn't specify when it returns null

Jan Lahoda jlahoda at openjdk.org
Tue May 13 11:34:32 UTC 2025


`InstanceOfTree.getType()` returns `null` if the `instanceof` uses a pattern different than the type test pattern. This is not documented, and should be documented. This PR proposes the documentation for this.

Alternatively, we could change `getType()` to return a type for other types of patterns, but the meaning of that is not quite clear even for record patterns, and it gets even less clear with the possible future patterns. I believe it has been mostly a conscious decision to not handle record patterns in this method. Possibly, it was a mistake to handle the type test/binding patterns in `getType()`, but that's not something that we should change, I think.

Please also review the CSR:
https://bugs.openjdk.org/browse/JDK-8356857

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

Commit messages:
 - Adding test.
 - 8348906: InstanceOfTree#getType doesn't specify when it returns null

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

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


More information about the compiler-dev mailing list