-
Bug
-
Resolution: Unresolved
-
P3
-
None
This class fails to compile in all JDKs with the commit that fixed JDK-8232933
```
import java.util.Set;
import java.util.TreeSet;
import java.util.concurrent.Callable;
import java.util.stream.Collectors;
import java.util.stream.Stream;
public class Reproducer {
public static void main(String[] args){
interface Interface {
<T> void runFun(T result, Callable<T> work);
}
Interface obj = null;
obj.runFun(Set.of(), () -> Set.of("works"));
obj.runFun(Set.of(), () -> new TreeSet<>(Set.of("works")));
obj.runFun(Set.of(), () -> Stream.of("works").collect(Collectors.toSet()));
obj.runFun(Set.of(), () -> Stream.of("broken in 17.0.10").collect(Collectors.toCollection(TreeSet::new))); // fails to compile
}
}
```
The error reads:
```
javac Reproducer.java
Reproducer.java:19: error: method runFun in interface Interface cannot be applied to given types;
obj.runFun(Set.of(), () -> Stream.of("broken in 17.0.10").collect(Collectors.toCollection(TreeSet::new)));
^
required: T,Callable<T>
found: Set<Object>,()->Stream[...]new))
reason: inferred type does not conform to equality constraint(s)
inferred: C
equality constraints(s): R
where T,C,R are type-variables:
T extends Object declared in method <T>runFun(T,Callable<T>)
C extends Collection<String>
R extends Collection<String>
1 error
```
```
import java.util.Set;
import java.util.TreeSet;
import java.util.concurrent.Callable;
import java.util.stream.Collectors;
import java.util.stream.Stream;
public class Reproducer {
public static void main(String[] args){
interface Interface {
<T> void runFun(T result, Callable<T> work);
}
Interface obj = null;
obj.runFun(Set.of(), () -> Set.of("works"));
obj.runFun(Set.of(), () -> new TreeSet<>(Set.of("works")));
obj.runFun(Set.of(), () -> Stream.of("works").collect(Collectors.toSet()));
obj.runFun(Set.of(), () -> Stream.of("broken in 17.0.10").collect(Collectors.toCollection(TreeSet::new))); // fails to compile
}
}
```
The error reads:
```
javac Reproducer.java
Reproducer.java:19: error: method runFun in interface Interface cannot be applied to given types;
obj.runFun(Set.of(), () -> Stream.of("broken in 17.0.10").collect(Collectors.toCollection(TreeSet::new)));
^
required: T,Callable<T>
found: Set<Object>,()->Stream[...]new))
reason: inferred type does not conform to equality constraint(s)
inferred: C
equality constraints(s): R
where T,C,R are type-variables:
T extends Object declared in method <T>runFun(T,Callable<T>)
C extends Collection<String>
R extends Collection<String>
1 error
```
- relates to
-
JDK-8232933 Javac inferred type does not conform to equality constraint
- Resolved