Lambda and parameterized ref of an inline type doesn't work well

Srikanth srikanth.adayapalam at oracle.com
Mon May 11 13:50:33 UTC 2020



On 08/05/20 8:36 pm, Remi Forax wrote:
> [move to valhalla-dev]
>
> Hi Srikanth,
> This seems to fix the lambda bug but not the one with the enhanced for loop.
> Here, the inline type is itself a generics so it should work as usual.

Sorry about the confusion and overlooking this case. This should work now
with https://github.com/openjdk/valhalla/pull/41/ being integrated.

Thanks!
Srikanth

>
>    @__inline__ static class Foo<V> implements Iterable<V> {
>      int x = 3;
>      
>      public Iterator<V> iterator() {
>        return null;
>      }
>    }
>
>
>    public static void main(String[] args) {
>      Foo<String> foo = new Foo<String>();
>      for(var s: foo) {
>      }
>    }
>
>
> $javac Hello.java
> Hello.java:15: error: for-each not applicable to expression type
>      for(var s: foo) {
>                 ^
>    required: array or java.lang.Iterable
>    found:    Foo<String>
> 1 error
>
> regards,
> Rémi
>
> ----- Mail original -----
>> De: "Srikanth" <srikanth.adayapalam at oracle.com>
>> À: "amber-dev" <amber-dev at openjdk.java.net>
>> Envoyé: Vendredi 8 Mai 2020 15:00:46
>> Objet: Re: Lambda and parameterized ref of an inline type doesn't work well
>> Hello Remi,
>>
>> Thanks for the report - this should be fixed by the commit
>> https://github.com/openjdk/valhalla/commit/e586cdbe made for
>> https://bugs.openjdk.java.net/browse/JDK-8244559
>>
>> With this all three problems reported are solved and should work now.
>>
>> (The inline + record synthesized methods is open)
>>
>> Srikanth
>>
>> On 07/05/20 4:07 am, Remi Forax wrote:
>>>     @__inline__ static class Foo<V> {
>>>       int x;
>>>       Foo(int x) { this.x = x; }
>>>     }
>>>
>>>     static void m(Foo foo) {
>>>       System.out.println("inline");
>>>     }
>>>     static void m(Foo.ref foo) {
>>>       System.out.println("ref");
>>>     }
>>>
>>>     public static void main(String[] args) {
>>>       List<Foo.ref<Integer>> list = List.of(new Foo<Integer>(3));
>>>       list.stream().forEach(e -> m(e));
>>>     }
>>>
>>> I don't even understand the error message when playing with parameterized ref of
>>> an inline type.
>>>
>>> error: cannot select a static class from a parameterized type
>>> Hello.java:19: error: incompatible types: incompatible parameter types in lambda
>>> expression
>>>       list.stream().forEach(e -> m(e));
>>>                             ^
>>>
>>> regards,
>>> Rémi



More information about the valhalla-dev mailing list