Bug 507371 - [1.8][inference] Cannot infer type argument(s) error
Summary: [1.8][inference] Cannot infer type argument(s) error
Status: NEW
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 4.6   Edit
Hardware: PC Windows NT
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: JDT-Core-Inbox CLA
QA Contact:
URL:
Whiteboard: stalebug
Keywords:
Depends on:
Blocks:
 
Reported: 2016-11-10 14:15 EST by Chin Bim CLA
Modified: 2022-11-29 08:17 EST (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Chin Bim CLA 2016-11-10 14:15:12 EST
For this piece of code:

interface IB<T> {
}

interface IC<T extends IB<U>, U> {
    void onMessage(T obj);
}

class MyClass {
    <T extends IB<U>, U> void setValue(IC<T, U> event) {
    }
}

class Foo {
    public static void main(String args[]) {
        MyClass tmp = new MyClass();
        tmp.setValue((event) -> {}); // error here
    }
}

I'm getting this error when using Eclipse Neon 4.6.1:

Cannot infer type argument(s) for <T, U> setValue(IC<T,U>)

but the same piece of code compiles fine using Eclipse 4.6.0 and Intellij IDEA 2016.2, or using javac.
Comment 1 Stephan Herrmann CLA 2016-11-10 15:06:57 EST
Fails since 4.5M3

Accepted by javac 9 (ea), too.

Inference doesn't get any useful hints regarding T and U, so we should probably expect the following solution:
 U = Object
 T = IB<Object>
Comment 2 Chin Bim CLA 2016-11-10 15:24:08 EST
I don't know about 4.5M3 but it works on 4.6.0 (I only saw this error the first time after updated to 4.6.1).
Comment 3 Stephan Herrmann CLA 2016-11-10 17:44:26 EST
Right, 4.6.0 accepts this, but since the fix for bug 496574, we report an error. That doesn't, however, mean that the fix for bug 496574 is to blame. This fix only exposes an inference failure, that previously was silently swallowed for no good reason.

4.5 M3 was the point in time, when bug 437444 introduced this "swallowing". This indicates that our inference probably never succeeded for this example.

Next we need to figure out *why* inference fails.
Comment 4 Manoj N Palat CLA 2018-05-16 01:30:40 EDT
Bulk move out of 4.8
Comment 5 Eclipse Genie CLA 2022-11-29 08:01:23 EST
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.
Comment 6 Stephan Herrmann CLA 2022-11-29 08:17:08 EST
(In reply to Stephan Herrmann from comment #1)
> Fails since 4.5M3
> 
> Accepted by javac 9 (ea), too.
> 
> Inference doesn't get any useful hints regarding T and U, so we should
> probably expect the following solution:
>  U = Object
>  T = IB<Object>

When declaring these types instead of asking type inference ecj accepts:

    tmp.<IB<Object>,Object>setValue((event) -> {});