mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
skip errors in case of diamond inference with type parameters on constructor
This commit is contained in:
+1
-3
@@ -16,14 +16,12 @@
|
||||
package com.intellij.psi.impl.source.resolve.graphInference;
|
||||
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.openapi.util.Computable;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.impl.source.resolve.ParameterTypeInferencePolicy;
|
||||
import com.intellij.psi.impl.source.resolve.graphInference.constraints.ExpressionCompatibilityConstraint;
|
||||
import com.intellij.psi.infos.MethodCandidateInfo;
|
||||
import com.intellij.psi.util.*;
|
||||
import com.intellij.util.Producer;
|
||||
import org.jetbrains.annotations.Contract;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
@@ -54,7 +52,7 @@ public class InferenceSessionContainer {
|
||||
final PsiSubstitutor callSession = findNestedSubstitutor(((PsiCallExpression)returnExpression).getArgumentList(), null);
|
||||
if (callSession == null) {
|
||||
final InferenceSession inferenceSession =
|
||||
ExpressionCompatibilityConstraint.reduceExpressionCompatibilityConstraint(session, returnExpression, returnType);
|
||||
ExpressionCompatibilityConstraint.reduceExpressionCompatibilityConstraint(session, returnExpression, returnType, false);
|
||||
if (inferenceSession != null && inferenceSession != session) {
|
||||
registerNestedSession(inferenceSession);
|
||||
session.propagateVariables(inferenceSession.getInferenceVariables(), inferenceSession.getRestoreNameSubstitution());
|
||||
|
||||
+7
-3
@@ -99,7 +99,7 @@ public class ExpressionCompatibilityConstraint extends InputOutputConstraintForm
|
||||
}
|
||||
|
||||
if (myExpression instanceof PsiCall) {
|
||||
final InferenceSession callSession = reduceExpressionCompatibilityConstraint(session, myExpression, myT);
|
||||
final InferenceSession callSession = reduceExpressionCompatibilityConstraint(session, myExpression, myT, true);
|
||||
if (callSession == null) {
|
||||
return false;
|
||||
}
|
||||
@@ -129,7 +129,8 @@ public class ExpressionCompatibilityConstraint extends InputOutputConstraintForm
|
||||
|
||||
public static InferenceSession reduceExpressionCompatibilityConstraint(InferenceSession session,
|
||||
PsiExpression expression,
|
||||
PsiType targetType) {
|
||||
PsiType targetType,
|
||||
boolean registerErrorOnFailure) {
|
||||
final PsiExpressionList argumentList = ((PsiCall)expression).getArgumentList();
|
||||
if (argumentList != null) {
|
||||
final MethodCandidateInfo.CurrentCandidateProperties candidateProperties = MethodCandidateInfo.getCurrentMethod(argumentList);
|
||||
@@ -152,6 +153,9 @@ public class ExpressionCompatibilityConstraint extends InputOutputConstraintForm
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
return session;
|
||||
}
|
||||
|
||||
if (typeParams != null) {
|
||||
PsiSubstitutor siteSubstitutor = InferenceSession.chooseSiteSubstitutor(candidateProperties, resolveResult, method);
|
||||
@@ -186,7 +190,7 @@ public class ExpressionCompatibilityConstraint extends InputOutputConstraintForm
|
||||
}
|
||||
return null;
|
||||
}
|
||||
else {
|
||||
else if (registerErrorOnFailure) {
|
||||
session.registerIncompatibleErrorMessage("Failed to resolve argument");
|
||||
return null;
|
||||
}
|
||||
|
||||
+31
@@ -0,0 +1,31 @@
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.function.Consumer;
|
||||
class MyTest {
|
||||
|
||||
static void createClass(Map<String, Object> templateAttributes,
|
||||
final Consumer<Integer> postProcessRunnable) {
|
||||
}
|
||||
|
||||
void f(Map<String, String> m) {
|
||||
final Ref<Integer> clazz = new Ref<>();
|
||||
createClass(
|
||||
new HashMap<>(foo(m)),
|
||||
i -> clazz.set(i)
|
||||
);
|
||||
}
|
||||
|
||||
private Map<String, String> foo(final Map<String, String> m) {
|
||||
return null;
|
||||
}
|
||||
|
||||
private class Ref<T> {
|
||||
void set(T t) {
|
||||
}
|
||||
}
|
||||
}
|
||||
class HashMap<K, V> extends java.util.HashMap<K, V> {
|
||||
public <K1 extends K, V1 extends V> HashMap(Map<? extends K1, ? extends V1> map) {
|
||||
super(map);
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -48,7 +48,7 @@ class Test2 {
|
||||
{
|
||||
Class c = D.class;
|
||||
|
||||
D<String> d = new D<error descr="Cannot infer arguments"><></error>(s -> s.<error descr="Cannot resolve method 'isEmpty()'">isEmpty</error>(), c);
|
||||
D<String> d = new D<>(s -> s.<error descr="Cannot resolve method 'isEmpty()'">isEmpty</error>(), c);
|
||||
D<String> d1 = D.create(s -> s.<error descr="Cannot resolve method 'isEmpty()'">isEmpty</error>(), c);
|
||||
}
|
||||
}
|
||||
+4
@@ -81,6 +81,10 @@ public class Diamond8HighlightingTest extends LightDaemonAnalyzerTestCase {
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testDiamondConstructorWithTypeParameters() throws Exception {
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testDiamondInsideOverloadedThisReference() throws Exception {
|
||||
doTest();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user