mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
method ref highlighting: show error on container when functional interface is not fully inferred (IDEA-214550)
GitOrigin-RevId: 8bce63a76385161033d494d1fd2b5439daccaf6d
This commit is contained in:
committed by
intellij-monorepo-bot
parent
f7b26dca7a
commit
1cfa8a070d
+2
-1
@@ -1332,6 +1332,8 @@ public class HighlightVisitorImpl extends JavaElementVisitor implements Highligh
|
||||
myHolder.add(checkFeature(expression, Feature.METHOD_REFERENCES));
|
||||
final PsiElement parent = PsiUtil.skipParenthesizedExprUp(expression.getParent());
|
||||
if (toReportFunctionalExpressionProblemOnParent(parent)) return;
|
||||
PsiType functionalInterfaceType = expression.getFunctionalInterfaceType();
|
||||
if (functionalInterfaceType != null && !PsiTypesUtil.allTypeParametersResolved(expression, functionalInterfaceType)) return;
|
||||
|
||||
final JavaResolveResult result;
|
||||
final JavaResolveResult[] results;
|
||||
@@ -1385,7 +1387,6 @@ public class HighlightVisitorImpl extends JavaElementVisitor implements Highligh
|
||||
}
|
||||
}
|
||||
|
||||
PsiType functionalInterfaceType = expression.getFunctionalInterfaceType();
|
||||
if (functionalInterfaceType != null) {
|
||||
if (!myHolder.hasErrorResults()) {
|
||||
boolean isFunctional = LambdaUtil.isFunctionalType(functionalInterfaceType);
|
||||
|
||||
+1
-1
@@ -10,7 +10,7 @@ class MyTest {
|
||||
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>)));
|
||||
from<error descr="Ambiguous method call: both 'MyTest.from(Page<String>)' and 'MyTest.from(Collection<String>)' match">(artifactStream.collect(Collectors.toCollection(TreeSet<String>::new)))</error>;
|
||||
}
|
||||
|
||||
interface Page<T> extends Iterable<T> {}
|
||||
|
||||
+1
-1
@@ -13,7 +13,7 @@ class Foo<R> {
|
||||
|
||||
public void foo() {
|
||||
reduce(Moo::new);
|
||||
reduce(<error descr="Bad return type in method reference: cannot convert Foo<R>.AMoo to S">AMoo::new</error>);
|
||||
reduce<error descr="'reduce(Foo.Factory<S>)' in 'Foo' cannot be applied to '(<method reference>)'">(AMoo::new)</error>;
|
||||
reduce(AAMoo::new);
|
||||
reduce(AAAMoo::new);
|
||||
}
|
||||
|
||||
+1
-1
@@ -7,7 +7,7 @@ interface B<BT> {
|
||||
|
||||
class Test {
|
||||
public static void test() {
|
||||
method1(Test::<error descr="Incompatible types: A<capture of ? super M> is not convertible to A<? super String>">method2</error>);
|
||||
method1<error descr="'method1(B<A<? super M>>)' in 'Test' cannot be applied to '(<method reference>)'">(Test::method2)</error>;
|
||||
}
|
||||
|
||||
static <M> void method1(B<A<? super M>> arg) { }
|
||||
|
||||
+23
@@ -0,0 +1,23 @@
|
||||
class Logger {}
|
||||
class Test {
|
||||
public static void main(String[] args) {
|
||||
User user = new User();
|
||||
Logger logger = null;
|
||||
|
||||
foo<error descr="'foo(T, java.util.logging.Logger, java.util.function.Function<T,java.lang.String>)' in 'Test' cannot be applied to '(User, Logger, <method reference>)'">(user, logger, User::getId)</error>;
|
||||
}
|
||||
|
||||
private static <T> void foo(T val, java.util.logging.Logger logger, java.util.function.Function<T, String> idFunction) { }
|
||||
}
|
||||
|
||||
class User {
|
||||
private String Id;
|
||||
|
||||
public String getId() {
|
||||
return Id;
|
||||
}
|
||||
|
||||
public void setId(String id) {
|
||||
this.Id = id;
|
||||
}
|
||||
}
|
||||
+1
@@ -194,6 +194,7 @@ public class NewMethodRefHighlightingTest extends LightDaemonAnalyzerTestCase {
|
||||
public void testPreferErrorOnTopLevelToFailedSubstitutorOnNestedLevel() { doTest(); }
|
||||
public void testDontIgnoreIncompatibilitiesDuringFirstApplicabilityCheck() { doTest(); }
|
||||
public void testCaptureOnDedicatedParameterOfSecondSearch() { doTest(); }
|
||||
public void testErrorMessageOnTopCallWhenFunctionalInterfaceIsNotInferred() { doTest(); }
|
||||
|
||||
private void doTest() {
|
||||
doTest(false);
|
||||
|
||||
Reference in New Issue
Block a user