UnreachableCode.getUnreachableTextRanges always returns at least one range #KT-14158 Fixed
This commit is contained in:
@@ -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!!)
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
$TESTDATA_DIR$/returnAsWhenKey.kt
|
||||
-d
|
||||
$TEMP_DIR$
|
||||
@@ -0,0 +1,7 @@
|
||||
// KT-14158: NoSuchElementException while compiling...
|
||||
|
||||
fun foo(): Int {
|
||||
when (true) {
|
||||
return 0 -> return 1
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
compiler/testData/cli/jvm/returnAsWhenKey.kt:5:17: warning: unreachable code
|
||||
return 0 -> return 1
|
||||
^
|
||||
compiler/testData/cli/jvm/returnAsWhenKey.kt:5:21: warning: unreachable code
|
||||
return 0 -> return 1
|
||||
^
|
||||
OK
|
||||
@@ -16,7 +16,7 @@ fun fff(): Int {
|
||||
var d = 3
|
||||
when(d) {
|
||||
4 -> <!UNUSED_EXPRESSION!>21<!>
|
||||
return 2 -> <!UNREACHABLE_CODE!>return 47<!>
|
||||
return 2<!UNREACHABLE_CODE!><!> -> <!UNREACHABLE_CODE!>return 47<!>
|
||||
<!UNREACHABLE_CODE!>bar() -> 45<!>
|
||||
<!UNREACHABLE_CODE!>444 -> true<!>
|
||||
}
|
||||
|
||||
@@ -253,6 +253,12 @@ public class CliTestGenerated extends AbstractCliTest {
|
||||
doJvmTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("returnAsWhenKey.args")
|
||||
public void testReturnAsWhenKey() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/cli/jvm/returnAsWhenKey.args");
|
||||
doJvmTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("sanitized-name.clash.args")
|
||||
public void testSanitized_name_clash() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/cli/jvm/sanitized-name.clash.args");
|
||||
|
||||
Reference in New Issue
Block a user