UnreachableCode.getUnreachableTextRanges always returns at least one range #KT-14158 Fixed

This commit is contained in:
Mikhail Glukhikh
2016-10-20 15:17:41 +03:00
parent 4fc135709e
commit bfaa9cf56f
6 changed files with 30 additions and 2 deletions
@@ -42,7 +42,12 @@ class UnreachableCodeImpl(
override fun getUnreachableTextRanges(element: KtElement): List<TextRange> {
return if (element.hasChildrenInSet(reachableElements)) {
element.getLeavesOrReachableChildren().removeReachableElementsWithMeaninglessSiblings().mergeAdjacentTextRanges()
with (element.getLeavesOrReachableChildren().removeReachableElementsWithMeaninglessSiblings().mergeAdjacentTextRanges()) {
if (isNotEmpty()) this
// Specific case like condition in when:
// element is dead but its only child is alive and has the same text range
else listOf(element.textRange.endOffset.let { TextRange(it, it) })
}
}
else {
listOf(element.textRange!!)