Add "unnecessary local variable" inspection #KT-15958 Fixed
This commit is contained in:
@@ -0,0 +1 @@
|
||||
org.jetbrains.kotlin.idea.inspections.UnnecessaryVariableInspection
|
||||
@@ -0,0 +1,5 @@
|
||||
fun test(): Int {
|
||||
val x = 1
|
||||
val <caret>y = x
|
||||
return x + y
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
fun test(): Int {
|
||||
val x = 1
|
||||
return x + x
|
||||
}
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
// PROBLEM: none
|
||||
|
||||
fun test(): Int {
|
||||
val x = 1
|
||||
// With explicitly given type looks dangerous
|
||||
val <caret>y: Int = x
|
||||
return x + y
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
// PROBLEM: none
|
||||
|
||||
fun test(): Int {
|
||||
var x = 1
|
||||
val <caret>y = x
|
||||
x++
|
||||
return x + y
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
fun sqr(arg: Int): Int {
|
||||
val <caret>other = arg
|
||||
return other * other
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fun sqr(arg: Int): Int {
|
||||
return arg * arg
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
// PROBLEM: none
|
||||
|
||||
class My(val x: Number)
|
||||
|
||||
fun My.foo(): Int {
|
||||
val <caret>y = x
|
||||
if (y is Int) return y
|
||||
return 0
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
fun sum(a: Int, b: Int): Int {
|
||||
val <caret>c = a + b
|
||||
return c
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fun sum(a: Int, b: Int): Int {
|
||||
return a + b
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
// PROBLEM: none
|
||||
|
||||
val x: Number? = null
|
||||
|
||||
fun foo(): Int {
|
||||
val <caret>y = x
|
||||
if (y is Int) return y
|
||||
return 0
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
// PROBLEM: none
|
||||
|
||||
fun sqrPlusOne(arg: Int): Int {
|
||||
var <caret>other = arg
|
||||
other++
|
||||
return other * other
|
||||
}
|
||||
Reference in New Issue
Block a user