Giorgio Vespucci
05/29/2025, 1:12 PM"Unreachable Code"
with K2 Mode active.
Has anyone got the same issue?dmitriy.novozhilov
05/29/2025, 1:23 PMGiorgio Vespucci
05/29/2025, 1:24 PMGiorgio Vespucci
05/29/2025, 2:09 PMconst val DASH_PREFIXED_INPUT_EXPECTED_RESULT = "I am reachable for any input prefixed by `-`"
const val NULL_INPUT_EXPECTED_RESULT = "I am reachable for any null input"
val ANY_OTHER_INPUT_EXPECTED_RESULT = null
fun main() {
check(unreachable("-hello") == DASH_PREFIXED_INPUT_EXPECTED_RESULT)
check(unreachable(null) == NULL_INPUT_EXPECTED_RESULT)
check(unreachable("goodbye") == null)
println("All good")
}
fun unreachable(input: String?): String? {
return input?.let {
return if (it.startsWith("-")) {
DASH_PREFIXED_INPUT_EXPECTED_RESULT
} else {
ANY_OTHER_INPUT_EXPECTED_RESULT
}
} ?: NULL_INPUT_EXPECTED_RESULT
}
Giorgio Vespucci
05/29/2025, 2:09 PMGiorgio Vespucci
05/29/2025, 2:13 PMdmitriy.novozhilov
05/29/2025, 2:16 PMreturn
inside let
, as it's effectively unused (at least in the example you've provided)Giorgio Vespucci
05/29/2025, 2:27 PMGiorgio Vespucci
05/29/2025, 2:27 PMdmitriy.novozhilov
05/29/2025, 2:44 PMRoman Golyshev
06/11/2025, 10:22 AMGiorgio Vespucci
06/11/2025, 10:24 AM