mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
don't open captures on type computation (IDEA-154968)
This commit is contained in:
@@ -146,7 +146,7 @@ public class TypeEvaluator {
|
||||
if (method != null) {
|
||||
final PsiParameter[] parameters = method.getParameterList().getParameters();
|
||||
final PsiExpression[] actualParms = call.getArgumentList().getExpressions();
|
||||
return PsiImplUtil.normalizeWildcardTypeByPosition(createMethodSubstitution(parameters, actualParms, method, call, resolveResult.getSubstitutor(), false).substitute(evaluateType(call.getMethodExpression())), expr);
|
||||
return PsiUtil.captureToplevelWildcards(createMethodSubstitution(parameters, actualParms, method, call, resolveResult.getSubstitutor(), false).substitute(evaluateType(call.getMethodExpression())), expr);
|
||||
}
|
||||
}
|
||||
else if (expr instanceof PsiPolyadicExpression) {
|
||||
|
||||
@@ -27,7 +27,6 @@ import com.intellij.openapi.util.Pair;
|
||||
import com.intellij.openapi.util.TextRange;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.impl.PsiImplUtil;
|
||||
import com.intellij.psi.impl.source.PsiImmediateClassType;
|
||||
import com.intellij.psi.javadoc.PsiDocTagValue;
|
||||
import com.intellij.psi.search.PsiSearchScopeUtil;
|
||||
@@ -865,7 +864,7 @@ public class TypeMigrationLabeler {
|
||||
}
|
||||
else if (element instanceof PsiVariable) {
|
||||
if (ref instanceof PsiReferenceExpression) {
|
||||
getTypeEvaluator().setType(new TypeMigrationUsageInfo(ref), PsiImplUtil.normalizeWildcardTypeByPosition(migrationType, (PsiReferenceExpression)ref));
|
||||
getTypeEvaluator().setType(new TypeMigrationUsageInfo(ref), PsiUtil.captureToplevelWildcards(migrationType, ref));
|
||||
}
|
||||
}
|
||||
else {
|
||||
|
||||
@@ -359,6 +359,10 @@ public class PsiImplUtil {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Types should be proceed by the callers themselves
|
||||
*/
|
||||
@Deprecated
|
||||
public static PsiType normalizeWildcardTypeByPosition(@NotNull PsiType type, @NotNull PsiExpression expression) {
|
||||
PsiUtilCore.ensureValid(expression);
|
||||
PsiUtil.ensureValidType(type);
|
||||
@@ -383,21 +387,6 @@ public class PsiImplUtil {
|
||||
}
|
||||
|
||||
private static PsiType doNormalizeWildcardByPosition(PsiType type, @NotNull PsiExpression expression, PsiExpression topLevel) {
|
||||
if (type instanceof PsiCapturedWildcardType) {
|
||||
final PsiWildcardType wildcardType = ((PsiCapturedWildcardType)type).getWildcard();
|
||||
if (expression instanceof PsiReferenceExpression && LambdaUtil.isLambdaReturnExpression(expression)) {
|
||||
return type;
|
||||
}
|
||||
|
||||
if (PsiUtil.isAccessedForWriting(topLevel)) {
|
||||
return wildcardType.isSuper() ? wildcardType.getBound() : PsiCapturedWildcardType.create(wildcardType, expression);
|
||||
}
|
||||
else {
|
||||
final PsiType upperBound = ((PsiCapturedWildcardType)type).getUpperBound();
|
||||
return upperBound instanceof PsiWildcardType ? doNormalizeWildcardByPosition(upperBound, expression, topLevel) : upperBound;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (type instanceof PsiWildcardType) {
|
||||
final PsiWildcardType wildcardType = (PsiWildcardType)type;
|
||||
|
||||
@@ -473,6 +473,10 @@ public class PsiOldInferenceHelper implements PsiInferenceHelper {
|
||||
}
|
||||
if (paramClass == null) return null;
|
||||
|
||||
if (arg instanceof PsiCapturedWildcardType) {
|
||||
arg = ((PsiCapturedWildcardType)arg).getUpperBound();
|
||||
}
|
||||
|
||||
if (!(arg instanceof PsiClassType)) return null;
|
||||
|
||||
JavaResolveResult argResult = ((PsiClassType)arg).resolveGenerics();
|
||||
|
||||
-4
@@ -25,7 +25,6 @@ import com.intellij.pom.java.LanguageLevel;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.impl.DebugUtil;
|
||||
import com.intellij.psi.impl.PsiClassImplUtil;
|
||||
import com.intellij.psi.impl.PsiImplUtil;
|
||||
import com.intellij.psi.impl.source.resolve.JavaResolveCache;
|
||||
import com.intellij.psi.impl.source.resolve.graphInference.InferenceSession;
|
||||
import com.intellij.psi.impl.source.resolve.graphInference.PsiPolyExpressionUtil;
|
||||
@@ -272,9 +271,6 @@ public class PsiMethodCallExpressionImpl extends ExpressionPsiElement implements
|
||||
return returnTypeErasure;
|
||||
}
|
||||
}
|
||||
if (!languageLevel.isAtLeast(LanguageLevel.JDK_1_8)) {
|
||||
return PsiImplUtil.normalizeWildcardTypeByPosition(substitutedReturnType, call);
|
||||
}
|
||||
return PsiUtil.captureToplevelWildcards(substitutedReturnType, call);
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -30,6 +30,6 @@ class Foo<T> {
|
||||
|
||||
public static void main(String[] args) {
|
||||
Foo<?> foo = getFoo();
|
||||
double value = (double) foo.getValue();
|
||||
double value = <error descr="Inconvertible types; cannot cast 'capture<?>' to 'double'">(double) foo.getValue()</error>;
|
||||
}
|
||||
}
|
||||
+2
-2
@@ -2,7 +2,7 @@ abstract class A<T, S extends T>
|
||||
{
|
||||
abstract S bar();
|
||||
void foo(A<Runnable[], ? extends Cloneable[]> a){
|
||||
<error descr="Incompatible types. Found: 'java.lang.Cloneable[]', required: 'java.lang.Runnable[]'">Runnable[] x = a.bar();</error>
|
||||
<error descr="Incompatible types. Found: 'capture<? extends java.lang.Cloneable[]>', required: 'java.lang.Runnable[]'">Runnable[] x = a.bar();</error>
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,7 +18,7 @@ abstract class AC<T, S>
|
||||
{
|
||||
abstract S bar();
|
||||
void foo(AC<Runnable[], ? extends Cloneable[]> a){
|
||||
<error descr="Incompatible types. Found: 'java.lang.Cloneable[]', required: 'java.lang.Runnable[]'">Runnable[] x = a.bar();</error>
|
||||
<error descr="Incompatible types. Found: 'capture<? extends java.lang.Cloneable[]>', required: 'java.lang.Runnable[]'">Runnable[] x = a.bar();</error>
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+2
-2
@@ -45,7 +45,7 @@ class VarianceTesting {
|
||||
VarianceTesting t = l1.get(0);
|
||||
l.add(new VarianceTesting());
|
||||
l.add(null);
|
||||
<error descr="Incompatible types. Found: 'java.lang.Object', required: 'VarianceTesting'">VarianceTesting t1 = l.get(0);</error>
|
||||
<error descr="Incompatible types. Found: 'capture<? super VarianceTesting>', required: 'VarianceTesting'">VarianceTesting t1 = l.get(0);</error>
|
||||
X<? extends VarianceTesting> x1 = null;
|
||||
x1.putAll(new ArrayList<VarianceTesting>());
|
||||
List<?> unknownlist = l;
|
||||
@@ -142,7 +142,7 @@ class S1 {
|
||||
}
|
||||
|
||||
void bar(List<? extends S1> k) {
|
||||
f(k, <error descr="'f(java.util.List<capture<? extends S1>>, capture<? extends S1>)' in 'S1' cannot be applied to '(java.util.List<capture<? extends S1>>, S1)'">k.get(0)</error>);
|
||||
f(k, <error descr="'f(java.util.List<capture<? extends S1>>, capture<? extends S1>)' in 'S1' cannot be applied to '(java.util.List<capture<? extends S1>>, capture<? extends S1>)'">k.get(0)</error>);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+17
@@ -0,0 +1,17 @@
|
||||
|
||||
import java.util.*;
|
||||
import java.util.function.*;
|
||||
|
||||
class Test {
|
||||
<E, K> HashMap<K, ArrayList<E>> foo(ArrayList<E> list, BiFunction<E, Comparable<E>, K> getKey) {
|
||||
return null;
|
||||
}
|
||||
|
||||
void bar(ArrayList<? extends Number> list) {
|
||||
HashMap<Integer, ? extends ArrayList<? extends Number>> foo = foo(list, (x, c) -> c.compareTo(x));
|
||||
}
|
||||
|
||||
Set<Integer> baz(ArrayList<? extends Number> list) {
|
||||
return foo(list, (x, c) -> c.compareTo(x)).keySet(); // False error in lambda: 'compareTo(capture<? extends java.lang.Number>)' in 'java.lang.Comparable' cannot be applied to '(java.lang.Number)'
|
||||
}
|
||||
}
|
||||
+4
@@ -308,6 +308,10 @@ public class NewLambdaHighlightingTest extends LightDaemonAnalyzerTestCase {
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testPreserveCapturedWildcardAsLambdaParameterType() throws Exception {
|
||||
doTest();
|
||||
}
|
||||
|
||||
private void doTest() {
|
||||
doTest(false);
|
||||
}
|
||||
|
||||
@@ -8,6 +8,10 @@ import org.jetbrains.annotations.NonNls;
|
||||
*/
|
||||
public class TypeInferenceTest extends Resolve15TestCase {
|
||||
public void testInferInCall1 () throws Exception {
|
||||
doTestObject();
|
||||
}
|
||||
|
||||
private void doTestObject() throws Exception {
|
||||
PsiReferenceExpression ref = configure();
|
||||
PsiType type = ref.getType();
|
||||
assertTrue(type instanceof PsiClassType);
|
||||
@@ -26,21 +30,11 @@ public class TypeInferenceTest extends Resolve15TestCase {
|
||||
}
|
||||
|
||||
public void testInferInAssign2() throws Exception {
|
||||
PsiReferenceExpression ref = configure();
|
||||
PsiType type = ref.getType();
|
||||
assertTrue(type instanceof PsiClassType);
|
||||
PsiType[] paramTypes = ((PsiClassType)type).getParameters();
|
||||
assertEquals(1, paramTypes.length);
|
||||
assertEquals(CommonClassNames.JAVA_LANG_OBJECT, paramTypes[0].getCanonicalText());
|
||||
doTestObject();
|
||||
}
|
||||
|
||||
public void testInferInCast () throws Exception {
|
||||
PsiReferenceExpression ref = configure();
|
||||
PsiType type = ref.getType();
|
||||
assertTrue(type instanceof PsiClassType);
|
||||
PsiType[] paramTypes = ((PsiClassType)type).getParameters();
|
||||
assertEquals(1, paramTypes.length);
|
||||
assertEquals(CommonClassNames.JAVA_LANG_OBJECT, paramTypes[0].getCanonicalText());
|
||||
doTestObject();
|
||||
}
|
||||
|
||||
public void testInferWithBounds () throws Exception {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
Types:
|
||||
PsiMethodCallExpression:p.get(0) : java.lang.Number
|
||||
PsiMethodCallExpression:p.get(0) : ? extends java.lang.Number
|
||||
PsiParameter:p : java.util.ArrayList<? extends java.lang.Number>
|
||||
PsiReferenceExpression:p : java.util.ArrayList<? extends java.lang.Number>
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
Types:
|
||||
PsiMethodCallExpression:p.get(0) : java.lang.Object
|
||||
PsiMethodCallExpression:p.get(0) : ? super java.lang.Number
|
||||
PsiParameter:p : java.util.ArrayList<? super java.lang.Number>
|
||||
PsiParameter:p2 : java.lang.Object
|
||||
PsiReferenceExpression:p : java.util.ArrayList<? super java.lang.Number>
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
Types:
|
||||
PsiMethodCallExpression:p.get(0) : java.lang.Object
|
||||
PsiMethodCallExpression:p.get(0) : ?
|
||||
PsiParameter:p : java.util.ArrayList<?>
|
||||
PsiParameter:p2 : java.lang.Object
|
||||
PsiReferenceExpression:p : java.util.ArrayList<?>
|
||||
|
||||
+1
-1
@@ -1,5 +1,5 @@
|
||||
Types:
|
||||
PsiMethodCallExpression:p.get(0) : java.lang.Number
|
||||
PsiMethodCallExpression:p.get(0) : ? extends java.lang.Number
|
||||
PsiParameter:p : java.lang.Integer[]
|
||||
PsiReferenceExpression:p : java.lang.Integer[]
|
||||
|
||||
|
||||
+1
-1
@@ -1,5 +1,5 @@
|
||||
Types:
|
||||
PsiMethodCallExpression:p.get(0) : java.lang.Number
|
||||
PsiMethodCallExpression:p.get(0) : ? extends java.lang.Number
|
||||
PsiParameter:p : java.lang.Number[]
|
||||
PsiReferenceExpression:p : java.lang.Number[]
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
Types:
|
||||
PsiMethodCallExpression:p.set(0, new Integer(8)) : java.lang.Number
|
||||
PsiMethodCallExpression:p.set(0, new Integer(8)) : ? extends java.lang.Number
|
||||
PsiParameter:p : java.util.ArrayList<? extends java.lang.Number>
|
||||
PsiReferenceExpression:p : java.util.ArrayList<? extends java.lang.Number>
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
Types:
|
||||
PsiMethodCallExpression:p.set(0, new Integer(8)) : java.lang.Object
|
||||
PsiMethodCallExpression:p.set(0, new Integer(8)) : ? super java.lang.Integer
|
||||
PsiParameter:p : java.util.ArrayList<? super java.lang.Integer>
|
||||
PsiReferenceExpression:p : java.util.ArrayList<? super java.lang.Integer>
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
Types:
|
||||
PsiMethodCallExpression:p.set(0, new Integer(8)) : java.lang.Object
|
||||
PsiMethodCallExpression:p.set(0, new Integer(8)) : ?
|
||||
PsiParameter:p : java.util.ArrayList<?>
|
||||
PsiReferenceExpression:p : java.util.ArrayList<?>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user