Integrated: 8310685: [lw5] adding support for null restricted types
Maurizio Cimadamore
mcimadamore at openjdk.org
Mon Jun 26 09:34:28 UTC 2023
On Fri, 23 Jun 2023 02:43:48 GMT, Vicente Romero <vromero at openjdk.org> wrote:
> initial support for null restricted types
src/jdk.compiler/share/classes/com/sun/tools/javac/code/Types.java line 1170:
> 1168: * make sure that the caller really wants to warn
> 1169: */
> 1170: if (s.isNonNullable() && warnStack.head.pos() != null) {
This is a bit odd. We are defining a type relationship - if "BOT" is not a subtype of T! that is fine, we should just return false. Giving an error seems a bit strange here (I don't think it is normal for subtyping to generate errors).
src/jdk.compiler/share/classes/com/sun/tools/javac/code/Types.java line 1246:
> 1244: && isSubtypeNoCapture(sup.getEnclosingType(),
> 1245: s.getEnclosingType());
> 1246: if (result && warnStack.head.pos() != null && s.hasNarrowerNullabilityThan(t)) {
I have memories of the previous implementation where we discussed maybe keeping subtyping routines as is, but adding some other check to validate the "polarity" of the type arguments. Wouldn't something similar work here too?
src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Check.java line 304:
> 302: }
> 303:
> 304: public void errBangTypes(DiagnosticPosition pos, Error errKey) {
perhaps this can be checkNonNullable?
src/jdk.compiler/share/classes/com/sun/tools/javac/jvm/Gen.java line 2128:
> 2126: if (tree.lhs.type.isNonNullable()) {
> 2127: code.emitop0(dup);
> 2128: genNullCheck(tree.rhs);
Should the null check always be generated even if we know that the RHS is non-nullable? (I'm not sure here)
-------------
PR Review Comment: https://git.openjdk.org/valhalla/pull/872#discussion_r1241890775
PR Review Comment: https://git.openjdk.org/valhalla/pull/872#discussion_r1241892023
PR Review Comment: https://git.openjdk.org/valhalla/pull/872#discussion_r1241892741
PR Review Comment: https://git.openjdk.org/valhalla/pull/872#discussion_r1241895974
More information about the valhalla-dev
mailing list