Bug 481649 - [1.8][compiler][inference] Cannot infer type arguments against a wildcard in the target type
Summary: [1.8][compiler][inference] Cannot infer type arguments against a wildcard in ...
Status: NEW
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 4.5.1   Edit
Hardware: PC Windows 8
: P3 major with 1 vote (vote)
Target Milestone: ---   Edit
Assignee: JDT-Core-Inbox CLA
QA Contact:
URL:
Whiteboard: stalebug
Keywords:
Depends on:
Blocks:
 
Reported: 2015-11-07 10:46 EST by Ole Sandum CLA
Modified: 2022-10-11 18:47 EDT (History)
3 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Ole Sandum CLA 2015-11-07 10:46:21 EST
The following code fails to compile at line 6 in Eclipse 4.5.1, however it does compile in JDK 1.8.0_60 using javac from the command line:

package test;

public class Test {

	public static void main(String[] args) {
        registerCommand(new Command<>(FooExecutor.class, data -> { //Line 6
        	
        }));
	}
	
	static void registerCommand(Command<?> command) {
		//Implementation irrelevant
	}

}

class Command<T extends CommandExecutor> {
	
	Command(Class<T> executorType, CommandHandler<T, ? extends CommandData<T>> handler) {
		
	}
	
}

interface CommandHandler<T extends CommandExecutor, D extends CommandData<T>> {
	void handle(D data);
}

interface CommandExecutor {
	//Implementation irrelevant
}

interface CommandData<T extends CommandExecutor> {
	//Implementation irrelevant
}

class FooExecutor implements CommandExecutor {
	//Implementation irrelevant
}

If I change line 6 to be (redundantly) more explicit, it compiles fine in Eclipse as well:

registerCommand(new Command<FooExecutor>(FooExecutor.class, (CommandData<FooExecutor> data) -> {
        	
}));



Surely this is a bug?
Comment 1 John Laekh CLA 2015-11-07 10:55:20 EST
I've been experiencing the exact same issue
Comment 2 Stephan Herrmann CLA 2015-11-29 11:24:50 EST
The following builds all produce different results:

4.5M2 (3 errors)

4.5M3 (2 errors)

4.5M4 (1 errors)

The latter behavior can still be seen in HEAD.

Similar to bug 483226 we cannot infer a type argument against a wildcard in the target type.


(In reply to Ole Sandum from comment #0)
> If I change line 6 to be (redundantly) more explicit, it compiles fine in
> Eclipse as well:

Whether or not that is redundant or mandatory still needs to be seen.
Comment 3 Manoj N Palat CLA 2018-05-16 01:30:23 EDT
Bulk move out of 4.8
Comment 4 Eclipse Genie CLA 2022-10-11 18:47:05 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.