Partial body resolve correctly handles elvis operator

This commit is contained in:
Valentin Kipyatkov
2015-03-24 22:35:18 +03:00
parent 176ba937ba
commit f3799a0ce7
6 changed files with 46 additions and 2 deletions
@@ -157,8 +157,9 @@ class PartialBodyResolveFilter(
}
fun addPlaces(name: SmartCastName, places: Collection<JetExpression>) {
assert(!places.isEmpty())
map.getOrPut(name, { ArrayList(places.size()) }).addAll(places)
if (places.isNotEmpty()) {
map.getOrPut(name, { ArrayList(places.size()) }).addAll(places)
}
}
fun addIfCanBeSmartCast(expression: JetExpression) {
@@ -185,6 +186,22 @@ class PartialBodyResolveFilter(
}
}
override fun visitBinaryExpression(expression: JetBinaryExpression) {
expression.acceptChildren(this)
if (expression.getOperationToken() == JetTokens.ELVIS) {
val left = expression.getLeft()
val right = expression.getRight()
if (left != null && right != null) {
val smartCastName = left.smartCastExpressionName()
if (smartCastName != null && filter(smartCastName)) {
val exits = collectAlwaysExitPoints(right)
addPlaces(smartCastName, exits)
}
}
}
}
override fun visitIfExpression(expression: JetIfExpression) {
val condition = expression.getCondition()
val thenBranch = expression.getThen()