Bug 511002 - [1.8][inference] Eclipse cannot compile code with diamond operator, no error with javac 1.8
Summary: [1.8][inference] Eclipse cannot compile code with diamond operator, no error ...
Status: NEW
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 4.6   Edit
Hardware: PC Windows 10
: P3 normal with 1 vote (vote)
Target Milestone: ---   Edit
Assignee: JDT-Core-Inbox CLA
QA Contact:
URL:
Whiteboard: stalebug
Keywords:
Depends on:
Blocks:
 
Reported: 2017-01-24 19:53 EST by Andrey Petrov CLA
Modified: 2022-07-05 17:12 EDT (History)
5 users (show)

See Also:


Attachments
A class which cannot be compiled by Eclipse, but no error with javac 1.8 (1.18 KB, application/octet-stream)
2017-01-24 19:53 EST, Andrey Petrov CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Andrey Petrov CLA 2017-01-24 19:53:36 EST
Created attachment 266444 [details]
A class which cannot be compiled by Eclipse, but no error with javac 1.8

Eclipse gives an error in line 16:
The method print(Long) in the type Test is not applicable for the arguments (Object)

Interesting that when lambda is replaced with method reference, the error goes  away.
Comment 1 Jay Arthanareeswaran CLA 2017-01-25 00:44:46 EST
I can confirm this happens in the latest I build - I20170124-0800.

I am sorry, I tried finding similar existing bugs but not sure which ones.

Stephan, could you take a look?
Comment 2 Stephan Herrmann CLA 2017-01-25 15:14:47 EST
(In reply to Jay Arthanareeswaran from comment #1)
> I can confirm this happens in the latest I build - I20170124-0800.
> 
> I am sorry, I tried finding similar existing bugs but not sure which ones.
> 
> Stephan, could you take a look?

sure

The program is rejected by all Java-8 enabled versions of ecj.
Comment 3 Stephan Herrmann CLA 2019-05-19 14:23:32 EDT
The workaround is: say new Wrapper<Integer,Long>() instead of new Wrapper<>().

Looks like inference cannot properly propagate from inner inference to outer diamond inference.

This is supported by the following variant (accepted by ecj, too):
//---
...
        ints.map(Wrapper.create(intNum -> converter.convert(intNum))).forEach(longNum -> print(longNum));
...
        static <T,R> Wrapper<T,R> create(Function <T,R> function) {
            return new Wrapper<>(function);
        }
//---

i.e., replacing the diamond with a static generic factory method avoids the problem, too.

Pushing information from inner inference to outer is a thorny issue, not for 4.12.
Comment 4 Eclipse Genie CLA 2022-07-05 17:12:03 EDT
This bug hasn't had any activity in quite some time. Maybe the problem got resolved, was a duplicate of something else, or became less pressing for some reason - or maybe it's still relevant but just hasn't been looked at yet.

If you have further information on the current state of the bug, please add it. The information can be, for example, that the problem still occurs, that you still want the feature, that more information is needed, or that the bug is (for whatever reason) no longer relevant.

--
The automated Eclipse Genie.