Fixed KT-5168 Smart completion includes null when comparing non-nullable value
#KT-5168 Fixed
This commit is contained in:
@@ -170,7 +170,7 @@ class ExpectedInfos(val bindingContext: BindingContext, val moduleDescriptor: Mo
|
|||||||
val otherOperand = if (expressionWithType == binaryExpression.getRight()) binaryExpression.getLeft() else binaryExpression.getRight()
|
val otherOperand = if (expressionWithType == binaryExpression.getRight()) binaryExpression.getLeft() else binaryExpression.getRight()
|
||||||
if (otherOperand != null) {
|
if (otherOperand != null) {
|
||||||
val expressionType = bindingContext[BindingContext.EXPRESSION_TYPE, otherOperand] ?: return null
|
val expressionType = bindingContext[BindingContext.EXPRESSION_TYPE, otherOperand] ?: return null
|
||||||
return listOf(ExpectedInfo(expressionType.makeNullable(), null))
|
return listOf(ExpectedInfo(expressionType, null))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -28,6 +28,7 @@ import java.util.*
|
|||||||
import org.jetbrains.jet.plugin.completion.*
|
import org.jetbrains.jet.plugin.completion.*
|
||||||
import org.jetbrains.jet.lang.types.lang.KotlinBuiltIns
|
import org.jetbrains.jet.lang.types.lang.KotlinBuiltIns
|
||||||
import org.jetbrains.jet.plugin.util.makeNotNullable
|
import org.jetbrains.jet.plugin.util.makeNotNullable
|
||||||
|
import org.jetbrains.jet.plugin.util.makeNullable
|
||||||
|
|
||||||
class SmartCompletion(val expression: JetSimpleNameExpression,
|
class SmartCompletion(val expression: JetSimpleNameExpression,
|
||||||
val resolveSession: ResolveSessionForBodies,
|
val resolveSession: ResolveSessionForBodies,
|
||||||
@@ -73,8 +74,14 @@ class SmartCompletion(val expression: JetSimpleNameExpression,
|
|||||||
}
|
}
|
||||||
|
|
||||||
val allExpectedInfos = ExpectedInfos(bindingContext, moduleDescriptor).calculate(expressionWithType) ?: return null
|
val allExpectedInfos = ExpectedInfos(bindingContext, moduleDescriptor).calculate(expressionWithType) ?: return null
|
||||||
val expectedInfos = allExpectedInfos.filter { !it.`type`.isError() }
|
val filteredExpectedInfos = allExpectedInfos.filter { !it.`type`.isError() }
|
||||||
if (expectedInfos.isEmpty()) return null
|
if (filteredExpectedInfos.isEmpty()) return null
|
||||||
|
|
||||||
|
// if we complete argument of == or !=, make types in expected info's nullable to allow nullable items too
|
||||||
|
val expectedInfos = if ((expressionWithType.getParent() as? JetBinaryExpression)?.getOperationToken() in setOf(JetTokens.EQEQ, JetTokens.EXCLEQ))
|
||||||
|
filteredExpectedInfos.map { ExpectedInfo(it.`type`.makeNullable(), it.tail) }
|
||||||
|
else
|
||||||
|
filteredExpectedInfos
|
||||||
|
|
||||||
val result = ArrayList<LookupElement>()
|
val result = ArrayList<LookupElement>()
|
||||||
|
|
||||||
@@ -112,7 +119,7 @@ class SmartCompletion(val expression: JetSimpleNameExpression,
|
|||||||
|
|
||||||
LambdaItems.addToCollection(result, functionExpectedInfos)
|
LambdaItems.addToCollection(result, functionExpectedInfos)
|
||||||
|
|
||||||
KeywordValues.addToCollection(result, expectedInfos, expressionWithType)
|
KeywordValues.addToCollection(result, filteredExpectedInfos/* use filteredExpectedInfos to not include null after == */, expressionWithType)
|
||||||
}
|
}
|
||||||
|
|
||||||
return result
|
return result
|
||||||
|
|||||||
@@ -9,6 +9,8 @@ fun f(e1: E, e2: E?, x: Any) {
|
|||||||
|
|
||||||
// EXIST: E.A
|
// EXIST: E.A
|
||||||
// EXIST: E.B
|
// EXIST: E.B
|
||||||
// EXIST: e2
|
// EXIST: { itemText:"e2" }
|
||||||
|
// ABSENT: { itemText:"!! e2" }
|
||||||
// ABSENT: e1
|
// ABSENT: e1
|
||||||
// ABSENT: x
|
// ABSENT: x
|
||||||
|
// ABSENT: null
|
||||||
|
|||||||
Reference in New Issue
Block a user