Add "Redundant nullable return type" inspection

^KT-19321 Fixed
This commit is contained in:
Toshiaki Kameyama
2020-08-16 01:06:20 +02:00
committed by Vladimir Dolzhenko
parent d703284d01
commit 8420c0b7c7
23 changed files with 297 additions and 0 deletions
@@ -0,0 +1 @@
org.jetbrains.kotlin.idea.inspections.RedundantNullableReturnTypeInspection
@@ -0,0 +1,5 @@
// PROBLEM: 'foo' always returns non-null type
// WITH_RUNTIME
fun foo(xs: List<Int>): Int?<caret> {
return xs.first()
}
@@ -0,0 +1,5 @@
// PROBLEM: 'foo' always returns non-null type
// WITH_RUNTIME
fun foo(xs: List<Int>): Int {
return xs.first()
}
@@ -0,0 +1,9 @@
// PROBLEM: none
// WITH_RUNTIME
fun foo(xs: List<Int>, b: Boolean): Int?<caret> {
if (b) {
return xs.first()
} else {
return xs.lastOrNull()
}
}
@@ -0,0 +1,8 @@
// PROBLEM: 'foo' always returns non-null type
fun foo(i: Int?): Int?<caret> {
if (i != null) {
return i
} else {
return 0
}
}
@@ -0,0 +1,8 @@
// PROBLEM: 'foo' always returns non-null type
fun foo(i: Int?): Int {
if (i != null) {
return i
} else {
return 0
}
}
@@ -0,0 +1,2 @@
// PROBLEM: none
fun foo(): String<caret> = ""
@@ -0,0 +1,4 @@
// PROBLEM: none
abstract class Foo {
open fun foo(): String?<caret> = ""
}
@@ -0,0 +1,3 @@
// PROBLEM: 'foo' always returns non-null type
// WITH_RUNTIME
fun foo(xs: List<Int>): Int?<caret> = xs.first()
@@ -0,0 +1,3 @@
// PROBLEM: 'foo' always returns non-null type
// WITH_RUNTIME
fun foo(xs: List<Int>): Int = xs.first()
@@ -0,0 +1,3 @@
// PROBLEM: none
// WITH_RUNTIME
fun foo(xs: List<Int>, b: Boolean): Int?<caret> = if (b) xs.first() else xs.lastOrNull()
@@ -0,0 +1,3 @@
// PROBLEM: 'foo' is always non-null type
val foo: Int?<caret>
get() = 1
@@ -0,0 +1,3 @@
// PROBLEM: 'foo' is always non-null type
val foo: Int
get() = 1
@@ -0,0 +1,5 @@
// PROBLEM: 'foo' is always non-null type
val foo: Int?<caret>
get() {
return 1
}
@@ -0,0 +1,5 @@
// PROBLEM: 'foo' is always non-null type
val foo: Int
get() {
return 1
}
@@ -0,0 +1,2 @@
// PROBLEM: 'foo' is always non-null type
val foo: String?<caret> = ""
@@ -0,0 +1,2 @@
// PROBLEM: 'foo' is always non-null type
val foo: String = ""
@@ -0,0 +1,2 @@
// PROBLEM: none
var foo: String?<caret> = ""