completion: presume fresh variables have always low bounds during completion

IDEA-190041
This commit is contained in:
Anna Kozlova
2018-06-01 11:12:35 +03:00
parent d5ac0965cf
commit 2c5117ba22
5 changed files with 37 additions and 0 deletions
@@ -66,4 +66,9 @@ public class CompletionParameterTypeInferencePolicy extends ProcessCandidatePara
public boolean isVarargsIgnored() {
return true;
}
@Override
public boolean inferLowerBoundForFreshVariables() {
return true;
}
}
@@ -42,4 +42,13 @@ public abstract class ParameterTypeInferencePolicy {
public boolean isVarargsIgnored() {
return false;
}
/**
* For infinite type declarations, like {@code Foo<T extends Foo<T>>}, inference introduces fake fresh "fixed" type parameters.
* These fresh parameters respect constraints, created during inference session. For completion, it makes sense to define lower bounds
* even if no appropriate constraints were detected, as probably the corresponding argument is currently completed.
*/
public boolean inferLowerBoundForFreshVariables() {
return false;
}
}
@@ -0,0 +1,9 @@
interface Foo<T extends Foo<T>> {
static <F extends Foo<F>> void foo(F f) {
bar(f);<caret>
}
static <B extends Foo<B>> void bar(B b) { }
}
@@ -0,0 +1,9 @@
interface Foo<T extends Foo<T>> {
static <F extends Foo<F>> void foo(F f) {
bar(<caret>);
}
static <B extends Foo<B>> void bar(B b) { }
}
@@ -224,6 +224,11 @@ public void testConvertToObjectStream() {
myFixture.complete(CompletionType.SMART, 1);
checkResultByFile("/" + getTestName(false) + "-out.java");
}
public void testLowerBoundOfFreshVariable() {
configureByTestName();
myFixture.complete(CompletionType.SMART, 1);
checkResultByFile("/" + getTestName(false) + "-out.java");
}
private void doTest() {
doTest(true);