check that inferred intersection type doesn't contain same generic type with different type arguments (IDEA-170325)

This commit is contained in:
Anna.Kozlova
2017-03-28 10:09:30 +02:00
parent 7561efbf46
commit 9f3dfc8629
3 changed files with 26 additions and 1 deletions
@@ -1265,7 +1265,13 @@ public class InferenceSession {
}
if (type instanceof PsiIntersectionType) {
final String conflictingConjunctsMessage = ((PsiIntersectionType)type).getConflictingConjunctsMessage();
String conflictingConjunctsMessage = ((PsiIntersectionType)type).getConflictingConjunctsMessage();
if (conflictingConjunctsMessage == null) {
if (findParameterizationOfTheSameGenericClass(var.getBounds(InferenceBound.UPPER), pair -> pair.first == null || pair.second == null || pair.first.equals(pair.second)) != null) {
//warn if upper bounds has same generic class with different type arguments
conflictingConjunctsMessage = type.getPresentableText(false);
}
}
if (conflictingConjunctsMessage != null) {
registerIncompatibleErrorMessage("Type parameter " + var.getParameter().getName() + " has incompatible upper bounds: " + conflictingConjunctsMessage);
return PsiType.NULL;
@@ -0,0 +1,15 @@
import java.util.*;
import java.util.stream.Collectors;
import java.util.stream.Stream;
class A {
void m(final Stream<String> stream){
Set<String> ALLOWED_PROPS = unmodifiableSet <error descr="'unmodifiableSet(java.util.Set<? extends java.lang.String>)' in 'A' cannot be applied to '(java.util.HashSet<java.lang.String>)'">(stream.collect(Collectors.toCollection(HashSet::new)))</error>;
}
public static <T1> Set<T1> unmodifiableSet(Set<? extends T1> s) {
return null;
}
}
@@ -174,6 +174,10 @@ public class GraphInferenceHighlightingTest extends LightDaemonAnalyzerTestCase
//public void _testAssignabilityOfStandaloneExpressionsDuringApplicabilityCheck() { doTest(); }
public void testRecursiveTypeWithCapture() { doTest(); }
public void testApplicabilityCheckFailsExpressionTypeCheckPasses() throws Exception {
doTest();
}
private void doTest() {
doTest(false);
}