Never take ExpectedInfo from outer expression "as is"

This commit is contained in:
Valentin Kipyatkov
2015-10-02 21:38:43 +03:00
parent da7c62e788
commit fd6244ac51
4 changed files with 27 additions and 2 deletions
@@ -432,10 +432,11 @@ class ExpectedInfos(
ifExpression.getElse() -> {
val ifExpectedInfo = calculate(ifExpression)
val thenType = ifExpression.getThen()?.let { bindingContext.getType(it) }
if (thenType != null && !thenType.isError())
val filteredInfo = if (thenType != null && !thenType.isError())
ifExpectedInfo.filter { it.matchingSubstitutor(thenType) != null }
else
ifExpectedInfo
return filteredInfo.copyWithNoAdditionalData()
}
else -> return null
@@ -452,10 +453,11 @@ class ExpectedInfos(
val leftTypeNotNullable = leftType?.makeNotNullable()
val expectedInfos = calculate(binaryExpression)
if (expectedInfos.isNotEmpty()) {
return if (leftTypeNotNullable != null)
val filteredInfo = if (leftTypeNotNullable != null)
expectedInfos.filter { it.matchingSubstitutor(leftTypeNotNullable) != null }
else
expectedInfos
return filteredInfo.copyWithNoAdditionalData()
}
else if (leftTypeNotNullable != null) {
return listOf(ExpectedInfo(leftTypeNotNullable, null, null))
@@ -605,6 +607,8 @@ class ExpectedInfos(
private fun String.unpluralize()
= StringUtil.unpluralize(this)
private fun Collection<ExpectedInfo>.copyWithNoAdditionalData() = map { it.copy(additionalData = null, itemOptions = ItemOptions.DEFAULT) }
}
val COMPARISON_TOKENS = setOf(JetTokens.EQEQ, JetTokens.EXCLEQ, JetTokens.EQEQEQ, JetTokens.EXCLEQEQEQ)
@@ -0,0 +1,9 @@
fun foo(p1: Int, p2: Int) {
}
fun bar(b: Boolean) {
foo(if (b) 1 else <caret>)
}
// ABSENT: p1
// ABSENT: p2
@@ -1497,6 +1497,12 @@ public class JSBasicCompletionTestGenerated extends AbstractJSBasicCompletionTes
doTest(fileName);
}
@TestMetadata("NotInElse.kt")
public void testNotInElse() throws Exception {
String fileName = JetTestUtils.navigationMetadata("idea/idea-completion/testData/basic/common/namedArguments/NotInElse.kt");
doTest(fileName);
}
@TestMetadata("NotOnlyNamedArguments.kt")
public void testNotOnlyNamedArguments() throws Exception {
String fileName = JetTestUtils.navigationMetadata("idea/idea-completion/testData/basic/common/namedArguments/NotOnlyNamedArguments.kt");
@@ -1497,6 +1497,12 @@ public class JvmBasicCompletionTestGenerated extends AbstractJvmBasicCompletionT
doTest(fileName);
}
@TestMetadata("NotInElse.kt")
public void testNotInElse() throws Exception {
String fileName = JetTestUtils.navigationMetadata("idea/idea-completion/testData/basic/common/namedArguments/NotInElse.kt");
doTest(fileName);
}
@TestMetadata("NotOnlyNamedArguments.kt")
public void testNotOnlyNamedArguments() throws Exception {
String fileName = JetTestUtils.navigationMetadata("idea/idea-completion/testData/basic/common/namedArguments/NotOnlyNamedArguments.kt");