mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-04-19 21:11:28 +07:00
new inference: raise a error when function type was not inferred (supposing well-formed type as free from wildcards)
(cherry picked from commit a9173e822d2aab629265baf295248950e2319e31)
This commit is contained in:
@@ -347,6 +347,8 @@ public class HighlightVisitorImpl extends JavaElementVisitor implements Highligh
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if (LambdaUtil.getFunctionalInterfaceType(expression, true) != null) {
|
||||
myHolder.add(HighlightInfo.newHighlightInfo(HighlightInfoType.ERROR).range(expression).descriptionAndTooltip("Cannot infer functional interface type").create());
|
||||
}
|
||||
}
|
||||
else {
|
||||
|
||||
@@ -18,6 +18,7 @@ package com.intellij.psi.impl.source.resolve.graphInference;
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.impl.source.resolve.graphInference.constraints.TypeEqualityConstraint;
|
||||
import com.intellij.psi.util.TypeConversionUtil;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public class FunctionalInterfaceParameterizationUtil {
|
||||
@@ -90,7 +91,7 @@ public class FunctionalInterfaceParameterizationUtil {
|
||||
}
|
||||
|
||||
final PsiClassType parameterization = elementFactory.createType(psiClass, session.infer());
|
||||
if (!isWildcardParameterized(parameterization)) return parameterization;
|
||||
if (!TypeConversionUtil.containsWildcards(parameterization)) return parameterization;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
import java.util.*;
|
||||
|
||||
class Test {
|
||||
interface I<T extends String, V extends List<T>> {
|
||||
T m(V p);
|
||||
}
|
||||
|
||||
void foo(I<? extends String, ? extends List<? extends String>> fip) { }
|
||||
|
||||
void test() {
|
||||
foo(<error descr="Cannot infer functional interface type">(ArrayList<? extends String> p) -> p.get(0)</error>);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -78,6 +78,10 @@ public class NewLambdaHighlightingTest extends LightDaemonAnalyzerTestCase {
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testUseCalculatedSubstitutor() throws Exception {
|
||||
doTest();
|
||||
}
|
||||
|
||||
private void doTest() {
|
||||
doTest(false);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user