Bug 576846 - Cannot infer type arguments in instanziation of generic class, when javac does compile
Summary: Cannot infer type arguments in instanziation of generic class, when javac doe...
Status: NEW
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 4.21   Edit
Hardware: PC All
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: JDT-Core-Inbox CLA
QA Contact:
URL:
Whiteboard: stalebug
Keywords:
Depends on:
Blocks:
 
Reported: 2021-10-22 09:48 EDT by Ingo Hadan CLA
Modified: 2024-03-29 05:30 EDT (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Ingo Hadan CLA 2021-10-22 09:48:59 EDT
In a scenario with generic classes and variadic arguments the java editor marks a line as error that the command line (jdk) java compiler (javac) does compile. It looks similar to e.g. 481649 but seems to be triggered by variadic arguments.

The following Program reproduces the issue:

import java.util.function.Function;
import java.util.function.Predicate;

public class GenericsBug<S> {
	public static interface MyInterface<U> {}
	
	public static class SubClass<U,V> implements MyInterface<V>{
		public SubClass(Function<U,V> g, MyInterface<V>... i) { }
    }
	
	public static class OptSubClass<U> implements MyInterface<U> {
		public OptSubClass(String s, Predicate<U> p, MyInterface<U>... i) { }

	}
	
	public static class ParamClass<T> {
		public T    getU()    { return null;}
	}
	
	GenericsBug(MyInterface<S> in1, MyInterface<S> in2) { }
	
	
	public static class MySubClass extends SubClass<ParamClass<Boolean>,Boolean> {
		public MySubClass() {
			super(ParamClass::getU);
		}
	}
	
	public static void foo() {
		SubClass<ParamClass<Boolean>,Boolean> sc = new SubClass<>(ParamClass::getU);
	    new GenericsBug<>(new MySubClass(),
	    		          new OptSubClass<>("foo", t->t, sc));
	}
};

The instanciation of GenericsBug yields the error "Cannot infer type arguments for GenericsBug<>" It may also be reproduced with ecj standalone.

-- Configuration Details --
Product: Eclipse IDE 4.21.0.20210910-1200 (org.eclipse.epp.package.jee.product)Installed Features:
 org.eclipse.jdt 3.18.900.v20210906-0500
Versioning Plugin:
 org.eclipse.platform 4.21.0.v20210906-0842
Comment 1 Andrey Loskutov CLA 2022-04-07 08:32:38 EDT
Still valid with I20220407-0240
Comment 2 Eclipse Genie CLA 2024-03-29 05:30:18 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.