inference: don't distinguish parameterizations with 2 different interfaces (IDEA...
authorAnna.Kozlova <anna.kozlova@jetbrains.com>
Tue, 15 Nov 2016 13:48:31 +0000 (14:48 +0100)
committerAnna.Kozlova <anna.kozlova@jetbrains.com>
Tue, 15 Nov 2016 17:11:31 +0000 (18:11 +0100)
java/java-psi-api/src/com/intellij/psi/util/TypesDistinctProver.java
java/java-tests/testData/codeInsight/daemonCodeAnalyzer/lambda/graphInference/TwoDifferentParameterizationCheckWithInterfaceTypeArguments.java [new file with mode: 0644]
java/java-tests/testSrc/com/intellij/codeInsight/daemon/lambda/GraphInferenceHighlightingTest.java

index e1ad149a4b0f9622d8db550fbf9c61a5f69a26c8..42a74d9f90348167b3a7823ed1b4d6f0ff4f7f2b 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright 2000-2010 JetBrains s.r.o.
+ * Copyright 2000-2016 JetBrains s.r.o.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -140,7 +140,12 @@ public class TypesDistinctProver {
       if (level < 2) return false;
     }
 
+    if (boundClass1 == null || boundClass2 == null) {
+      return type1 != null && type2 != null && !type1.equals(type2);
+    }
+
     return type2 != null && type1 != null && !type1.equals(type2) &&
+           !(boundClass1.isInterface() && boundClass2.isInterface()) &&
            (!InheritanceUtil.isInheritorOrSelf(boundClass1, boundClass2, true) ||
             !InheritanceUtil.isInheritorOrSelf(boundClass2, boundClass1, true));
   }
diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/lambda/graphInference/TwoDifferentParameterizationCheckWithInterfaceTypeArguments.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/lambda/graphInference/TwoDifferentParameterizationCheckWithInterfaceTypeArguments.java
new file mode 100644 (file)
index 0000000..c6c2140
--- /dev/null
@@ -0,0 +1,28 @@
+class Test {
+
+  {
+    Marker<String> cm = forEach(child1(), child2());
+  }
+
+  public static <D> Child1<D> child1() {
+    return null;
+  }
+
+  public static <S> Child2<S> child2() {
+    return null;
+  }
+
+  public static <F, CM extends Marker<F>> CM forEach(CM contents, CM cm) {
+    return null;
+  }
+
+  interface Marker<A> {}
+  static class Parent<S> {}
+
+  static class Child1<D> extends Parent<ChildAttr1> implements Marker<D> {}
+  interface ChildAttr1 {}
+
+  static class Child2<S> extends Parent<ChildAttr2> implements Marker<S> {}
+  interface ChildAttr2 {}
+
+}
index f04d7a0690c608d78e6e5eb0cf3076b3429c79f3..b402caf50635e2a0674a2a9be43c20315a934c87 100644 (file)
@@ -487,6 +487,10 @@ public class GraphInferenceHighlightingTest extends LightDaemonAnalyzerTestCase
     doTest();
   }
 
+  public void testTwoDifferentParameterizationCheckWithInterfaceTypeArguments() throws Exception {
+    doTest();
+  }
+
   private void doTest() throws Exception {
     doTest(false);
   }