Fix false positive "Foldable if-then" with Result type

#KT-27074 Fixed
This commit is contained in:
Dmitry Gridin
2019-06-04 15:47:15 +07:00
parent f2accb7b9e
commit b3fe830b6e
7 changed files with 94 additions and 12 deletions
@@ -0,0 +1,11 @@
// DISABLE-ERRORS
class Result<T> {
fun getOrNull(): Any = TODO()
}
val someNullableString: String? = ""
fun String.bar(): Result<String> = Result.success("")
val result = if<caret> (someNullableString == null) {
null
} else {
someNullableString.bar().getOrNull().let { }
}
@@ -0,0 +1,7 @@
// DISABLE-ERRORS
class Result<T> {
fun getOrNull(): Any = TODO()
}
val someNullableString: String? = ""
fun String.bar(): Result<String> = Result.success("")
val result = someNullableString?.bar()?.getOrNull()?.let { }
@@ -0,0 +1,11 @@
// PROBLEM: none
// WITH_RUNTIME
// DISABLE-ERRORS
val someNullableString: String? = ""
fun String.bar(): Result<String> = Result.success("")
val result = if<caret> (someNullableString == null) {
null
} else {
someNullableString.bar().getOrNull().let { }
}
@@ -0,0 +1,10 @@
// DISABLE-ERRORS
// WITH_RUNTIME
val someNullableString: String? = ""
fun String.bar(): Result<String> = Result.success("")
val result = if<caret> (someNullableString == null) {
null
} else {
someNullableString.bar()
}
@@ -0,0 +1,6 @@
// DISABLE-ERRORS
// WITH_RUNTIME
val someNullableString: String? = ""
fun String.bar(): Result<String> = Result.success("")
val result = someNullableString?.bar()