RFR: Improve support for nullable types and arrays

Maurizio Cimadamore mcimadamore at openjdk.org
Wed Aug 28 12:05:11 UTC 2024


This PR improves general support for arrays with `!` and `?` nullness markers.

The parser was parsing nullness markers associated to array brackets "backwards" - that is, when we have a type like this:


String* []? []!


* `*` should refer to `String`
* `?` should refer to the outermost array type
* `!` should refer to the innermost array type

The same is true with an array creation expression, like:


new String*[3]?[]!


(in this case, one might even wonder what sense does it make to say `?` for an array dimension that is going to be filled with `null` elements, but that's for another day).

Most of the `toString` implementation for array types and array trees were also wrong and they either dropped markers, or they displayed them in the "wrong order". So I've fixed that too (which helps when debugging).

Finally, I realized that there were no nullness warnings generated when going from nullable arrays to non-nullable arrays, so I've added some more code in `Types` for that.

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

Commit messages:
 - Revert spurious auto-formatting applied by IntelliJ
 - Fix parsing of multi-dimensional nullable array types
 - Initial work

Changes: https://git.openjdk.org/valhalla/pull/1227/files
  Webrev: https://webrevs.openjdk.org/?repo=valhalla&pr=1227&range=00
  Stats: 237 lines in 12 files changed: 188 ins; 16 del; 33 mod
  Patch: https://git.openjdk.org/valhalla/pull/1227.diff
  Fetch: git fetch https://git.openjdk.org/valhalla.git pull/1227/head:pull/1227

PR: https://git.openjdk.org/valhalla/pull/1227


More information about the valhalla-dev mailing list