method reference: registry option to skip unsound capture conversion specified in the spec but ignored by the javac, to be changed in the next spec version (IDEA-171488)

This commit is contained in:
Anna.Kozlova
2017-04-18 15:03:44 +02:00
parent a3dca1423c
commit c322dd3807
4 changed files with 29 additions and 5 deletions
@@ -16,6 +16,7 @@
package com.intellij.psi.impl.source.resolve.graphInference.constraints;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.util.registry.Registry;
import com.intellij.psi.*;
import com.intellij.psi.impl.source.resolve.graphInference.FunctionalInterfaceParameterizationUtil;
import com.intellij.psi.impl.source.resolve.graphInference.InferenceSession;
@@ -125,8 +126,10 @@ public class PsiMethodReferenceCompatibilityConstraint implements ConstraintForm
}
if (applicableMethodReturnType != null) {
final PsiType capturedReturnType = PsiUtil.captureToplevelWildcards(psiSubstitutor.substitute(applicableMethodReturnType), myExpression);
constraints.add(new TypeCompatibilityConstraint(returnType, session.substituteWithInferenceVariables(capturedReturnType)));
applicableMethodReturnType = psiSubstitutor.substitute(applicableMethodReturnType);
applicableMethodReturnType = Registry.is("unsound.capture.conversion.java.spec.change") ? applicableMethodReturnType
: PsiUtil.captureToplevelWildcards(applicableMethodReturnType, myExpression);
constraints.add(new TypeCompatibilityConstraint(returnType, session.substituteWithInferenceVariables(applicableMethodReturnType)));
}
}
return true;
@@ -164,7 +167,7 @@ public class PsiMethodReferenceCompatibilityConstraint implements ConstraintForm
if (element instanceof PsiMethod) {
final PsiMethod method = (PsiMethod)element;
final PsiType referencedMethodReturnType;
PsiType referencedMethodReturnType;
final PsiClass containingClass = method.getContainingClass();
LOG.assertTrue(containingClass != null, method);
PsiSubstitutor psiSubstitutor = getSubstitutor(signature, qualifierResolveResult, method, containingClass, myExpression);
@@ -211,8 +214,10 @@ public class PsiMethodReferenceCompatibilityConstraint implements ConstraintForm
session.initBounds(myExpression, containingClass.getTypeParameters());
}
final PsiType capturedReturnType = PsiUtil.captureToplevelWildcards(psiSubstitutor.substitute(referencedMethodReturnType), myExpression);
constraints.add(new TypeCompatibilityConstraint(returnType, session.substituteWithInferenceVariables(capturedReturnType)));
referencedMethodReturnType = psiSubstitutor.substitute(referencedMethodReturnType);
referencedMethodReturnType = Registry.is("unsound.capture.conversion.java.spec.change") ? referencedMethodReturnType
: PsiUtil.captureToplevelWildcards(referencedMethodReturnType, myExpression);
constraints.add(new TypeCompatibilityConstraint(returnType, session.substituteWithInferenceVariables(referencedMethodReturnType)));
}
return true;
@@ -0,0 +1,15 @@
import java.util.Optional;
import java.util.function.Function;
abstract class View {
{
foo(View::returnType).orElse(void.class);
}
abstract <H> Optional<H> foo(Function<View, H> f);
public Class<?> returnType() {
return null;
}
}
@@ -156,6 +156,7 @@ public class NewMethodRefHighlightingTest extends LightDaemonAnalyzerTestCase {
public void testGetClassReturnTypeInMethodReference() { doTest(); }
public void testCaptureTypeOfNewArrayExpression() { doTest(); }
public void testIDEA152659() { doTest(); }
public void testRegistryOptionToSkipUnsoundCaptureConversionInMethodReferenceReturnType() { doTest(); }
public void testFreshVariableLowerBoundsDuringSuperTypeChecks() { doTest(); }
public void testTypeParameterInstantiation() { doTest(); }
public void testIgnoreForeignVariables() { doTest(); }
@@ -809,6 +809,9 @@ javac.fresh.variables.for.captured.wildcards.only=true
javac.fresh.variables.for.captured.wildcards.only.description=JLS 18.5.2: if R \u03B8 is a parameterized type, G<A1, ..., An>, and one of A1, ..., An is a wildcard, then, for fresh inference variables \u03B21, ..., \u03B2n ... \
Javac creates fresh variables only for i: Ai is a wildcard
unsound.capture.conversion.java.spec.change=true
unsound.capture.conversion.java.spec.change.description=Capture in method reference return type is unsound and the spec would be changed, see https://bugs.openjdk.java.net/browse/JDK-8170887
check.power.supply.for.mbp=false
check.power.supply.for.mbp.description=Check for discrete video card and power supply on MBPs