checked exception compatibility constraint: don't substitute with inferred variables as types are already constructed based on substituted values, so avoid dbl substitution which leads to errors in case of references to the containing method (IDEA-166104)

This commit is contained in:
Anna.Kozlova
2017-01-02 12:24:19 +01:00
parent d33ee0ad81
commit 178e834fb9
3 changed files with 18 additions and 2 deletions

View File

@@ -83,7 +83,7 @@ public class CheckedExceptionCompatibilityConstraint extends InputOutputConstrai
if (myExpression instanceof PsiLambdaExpression && !((PsiLambdaExpression)myExpression).hasFormalParameterTypes() ||
myExpression instanceof PsiMethodReferenceExpression && !((PsiMethodReferenceExpression)myExpression).isExact()) {
for (PsiParameter parameter : interfaceMethod.getParameterList().getParameters()) {
final PsiType type = session.substituteWithInferenceVariables(substitutor.substitute(parameter.getType()));
final PsiType type = substitutor.substitute(parameter.getType());
if (!session.isProperType(type)) {
session.registerIncompatibleErrorMessage("Parameter type is not yet inferred: " + session.getPresentableText(type));
return false;
@@ -93,7 +93,7 @@ public class CheckedExceptionCompatibilityConstraint extends InputOutputConstrai
final PsiType returnType = interfaceMethod.getReturnType();
if (myExpression instanceof PsiLambdaExpression || !((PsiMethodReferenceExpression)myExpression).isExact()) {
final PsiType type = session.substituteWithInferenceVariables(substitutor.substitute(returnType));
final PsiType type = substitutor.substitute(returnType);
if (!session.isProperType(type)) {
session.registerIncompatibleErrorMessage("Return type is not yet inferred: " + session.getPresentableText(type));
return false;

View File

@@ -0,0 +1,12 @@
import java.util.List;
import java.util.stream.Stream;
interface TreeUtils {
static <K> Stream<List<K>> treeStream(List<K> treeItem) {
Stream<List<K>> stream = null;
stream.flatMap(TreeUtils::treeStream);
return null;
}
}

View File

@@ -537,6 +537,10 @@ public class NewMethodRefHighlightingTest extends LightDaemonAnalyzerTestCase {
doTest();
}
public void testMethodREfToContainingMethodWithGenericParam() throws Exception {
doTest();
}
private void doTest() {
doTest(false);
}