[lworld] RFR: 8237072: [lworld] Add support for denoting and deriving the reference projection

Maurizio Cimadamore mcimadamore at openjdk.java.net
Fri May 1 00:44:16 UTC 2020


On Fri, 1 May 2020 00:10:19 GMT, Maurizio Cimadamore <mcimadamore at openjdk.org> wrote:

>> I've tried to reproduce the checkcast issue mentioned by Mauricio with this code:
>> public class Test2 {
>>     static inline class V {
>> 	int y = 52;
>>     }
>> 
>>     static void m(V.ref vr) {
>> 	V v = vr;
>>     }
>> 
>>     public static void main(String[] args) {
>> 	m(null);
>>     }
>> }
>> But I got an NPE where it was expected:
>> $ ./build/pull32/jdk/bin/java Test2
>> Exception in thread "main" java.lang.NullPointerException
>> 	at Test2.m(Test2.java:7)
>> 	at Test2.main(Test2.java:11)
>
>> But I got an NPE where it was expected:
> 
> My bad - I realized that the test I put together was only compiling and not executing - sorry for the noise.

> // Problem: 3, we infer a stream of X.ref's causing
>     // the method reference to not type check.
>     void unbound_lookup_with_projected_receiver() {
>         X [] a = new X[0];
>         Arrays.stream(a).map(X::data).filter(p -> p != null).forEach(System.out::println);
> /*
> error: incompatible types: invalid method reference
>         Arrays.stream(a).map(X::data).filter(p -> p != null).forEach(System.out::println);
>                              ^
>     method data in class X cannot be applied to given types
>       required: no arguments
>       found:    X$ref
>       reason: actual and formal argument lists differ in length

For this one, I think something that an approach that could be discussed would be to consider the method reference
`V::m`, where `V` is an inline class, in the same way as we consider `List::add`. That is, we have `class name::member
name`.

In such cases we infer the right parameterization from the context; here it would be nice if we could infer the right
val/ref from the context too.

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

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


More information about the valhalla-dev mailing list