[lworld] RFR: 8280382: [lworld] JCWithField AST node support should evolve to work with value classes

Aggelos Biboudis duke at openjdk.java.net
Fri Jan 28 09:31:41 UTC 2022


On Fri, 28 Jan 2022 05:21:20 GMT, Srikanth Adayapalam <sadayapalam at openjdk.org> wrote:

>> This PR ports basic `withField` tests from lworld-values to value-objects and extending some areas of code to support `withField` within value classes.
>> 
>> Nitpicking and a note: one of the error messages is now `compiler.err.primitive.or.value.class.instance.field.expected.here`. Would you propose to disambiguate further depending whether we are inside a `primitive` or a `value` class?
>
> src/jdk.compiler/share/classes/com/sun/tools/javac/code/Types.java line 615:
> 
>> 613:                     !t.hasTag(BOT) && isSubtype(t, s.referenceProjectionOrSelf());
>> 614:         }
>> 615: 
> 
> These changes are not necessary and in fact are incorrect. See that with this change, the following code does not compile anymore which it should.
> 
> 
> public value class X {
>     public static void main(String[] args) {
>         X x = null;
>     }
> }
> 
> 
> This triggers an error: 
> X.java:3: error: incompatible types: <null> cannot be converted to X
>         X x = null;
>               ^
> 
> X being a B2 value class its instances are very much nullable.

You are right. The idea behind it was that I was getting a null reference exception on the subtype check. `t.referenceProjection()` was returning `null`  and it was blowing up on the `t.equalsIgnoreMetadata(s)`. The triggering code was something like the following (so the reference projection of `o`  was `null`).


value static final class V {}

Object o = V.default;


What do you think?

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

PR: https://git.openjdk.java.net/valhalla/pull/621



More information about the valhalla-dev mailing list