inference: check substituted intersection type during resolution

This commit is contained in:
Anna.Kozlova
2017-12-06 14:13:58 +01:00
parent 9a929629f5
commit 6180b5b337
3 changed files with 22 additions and 1 deletions

View File

@@ -1246,7 +1246,10 @@ public class InferenceSession {
if (type instanceof PsiIntersectionType) {
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) {
if (findParameterizationOfTheSameGenericClass(var.getBounds(InferenceBound.UPPER),
pair -> pair.first == null || pair.second == null ||
Comparing.equal(substituteNonProperBound(pair.first, substitutor),
substituteNonProperBound(pair.second, substitutor))) != null) {
//warn if upper bounds has same generic class with different type arguments
conflictingConjunctsMessage = type.getPresentableText(false);
}

View File

@@ -0,0 +1,17 @@
import java.util.Collection;
import java.util.TreeSet;
import java.util.stream.Collectors;
import java.util.stream.Stream;
class MyTest {
public <T> void from(Page<T> elements) { }
public <T> void from(Collection<T> elements) { }
public void foo(final Stream<String> artifactStream) {
from(artifactStream.collect(Collectors.toCollection(<error descr="Bad return type in method reference: cannot convert java.util.TreeSet<java.lang.String> to C">TreeSet<String>::new</error>)));
}
interface Page<T> extends Iterable<T> {}
}

View File

@@ -184,6 +184,7 @@ public class GraphInferenceHighlightingTest extends LightDaemonAnalyzerTestCase
public void testPertinentToApplicabilityCheckForBlockLambda() { doTest(); }
public void testCheckGlbConflictsAfterIntersectionTypeCreated() { doTest(); }
public void testRestoreCapturedWildcardsInReturnTypesWhenNoAdditionalConstraintsDetected() { doTest(); }
public void testIntersectionWithSameInterfaceButDifferentTypeArgument() { doTest(); }
public void testVarargsMethodPreferred() { doTest(); }
public void testApplicabilityCheckFailsExpressionTypeCheckPasses() {