Unnecessary local variable: highlight with INFORMATION level when initializer has any multi-line blocks (#3359)

#KT-26752 Fixed
This commit is contained in:
Toshiaki Kameyama
2021-05-20 18:12:41 +09:00
committed by GitHub
parent e82857996f
commit b9a4b60b93
20 changed files with 273 additions and 0 deletions
@@ -0,0 +1,13 @@
// HIGHLIGHT: INFORMATION
fun test(b: Boolean): Int {
val <caret>result = if (b) {
foo()
} else {
bar()
}
return result
}
fun foo() = 1
fun bar() = 2
@@ -0,0 +1,12 @@
// HIGHLIGHT: INFORMATION
fun test(b: Boolean): Int {
return if (b) {
foo()
} else {
bar()
}
}
fun foo() = 1
fun bar() = 2
@@ -0,0 +1,9 @@
// HIGHLIGHT: GENERIC_ERROR_OR_WARNING
fun test(b: Boolean): Int {
val <caret>result = if (b) foo() else bar()
return result
}
fun foo() = 1
fun bar() = 2
@@ -0,0 +1,8 @@
// HIGHLIGHT: GENERIC_ERROR_OR_WARNING
fun test(b: Boolean): Int {
return if (b) foo() else bar()
}
fun foo() = 1
fun bar() = 2
@@ -0,0 +1,12 @@
// HIGHLIGHT: GENERIC_ERROR_OR_WARNING
fun test(b: Boolean): Int {
val <caret>result = if (b)
foo()
else
bar()
return result
}
fun foo() = 1
fun bar() = 2
@@ -0,0 +1,11 @@
// HIGHLIGHT: GENERIC_ERROR_OR_WARNING
fun test(b: Boolean): Int {
return if (b)
foo()
else
bar()
}
fun foo() = 1
fun bar() = 2
@@ -0,0 +1,14 @@
// HIGHLIGHT: GENERIC_ERROR_OR_WARNING
fun test(b: Boolean): Int {
val <caret>result = if (b)
baz { foo() }
else
baz { bar() }
return result
}
fun foo() = 1
fun bar() = 2
fun baz(f: () -> Int) = f()
@@ -0,0 +1,13 @@
// HIGHLIGHT: GENERIC_ERROR_OR_WARNING
fun test(b: Boolean): Int {
return if (b)
baz { foo() }
else
baz { bar() }
}
fun foo() = 1
fun bar() = 2
fun baz(f: () -> Int) = f()
@@ -0,0 +1,18 @@
// HIGHLIGHT: INFORMATION
fun test(b: Boolean): Int {
val <caret>result = if (b)
baz {
foo()
}
else
baz {
bar()
}
return result
}
fun foo() = 1
fun bar() = 2
fun baz(f: () -> Int) = f()
@@ -0,0 +1,17 @@
// HIGHLIGHT: INFORMATION
fun test(b: Boolean): Int {
return if (b)
baz {
foo()
}
else
baz {
bar()
}
}
fun foo() = 1
fun bar() = 2
fun baz(f: () -> Int) = f()
@@ -0,0 +1,9 @@
// HIGHLIGHT: GENERIC_ERROR_OR_WARNING
fun test(): Int {
val <caret>result = foo { bar() }
return result
}
fun foo(f: () -> Int) = f()
fun bar() = 1
@@ -0,0 +1,8 @@
// HIGHLIGHT: GENERIC_ERROR_OR_WARNING
fun test(): Int {
return foo { bar() }
}
fun foo(f: () -> Int) = f()
fun bar() = 1
@@ -0,0 +1,11 @@
// HIGHLIGHT: INFORMATION
fun test(): Int {
val <caret>result = foo {
bar()
}
return result
}
fun foo(f: () -> Int) = f()
fun bar() = 1
@@ -0,0 +1,10 @@
// HIGHLIGHT: INFORMATION
fun test(): Int {
return foo {
bar()
}
}
fun foo(f: () -> Int) = f()
fun bar() = 1
@@ -0,0 +1,13 @@
// HIGHLIGHT: INFORMATION
fun test(): Int {
val <caret>result = try {
foo()
} finally {
bar()
}
return result
}
fun foo() = 1
fun bar() {}
@@ -0,0 +1,12 @@
// HIGHLIGHT: INFORMATION
fun test(): Int {
return try {
foo()
} finally {
bar()
}
}
fun foo() = 1
fun bar() {}
@@ -0,0 +1,12 @@
// HIGHLIGHT: INFORMATION
fun test(i: Int): Int {
val <caret>result = when (i) {
1 -> foo()
else -> bar()
}
return result
}
fun foo() = 1
fun bar() = 2
@@ -0,0 +1,11 @@
// HIGHLIGHT: INFORMATION
fun test(i: Int): Int {
return when (i) {
1 -> foo()
else -> bar()
}
}
fun foo() = 1
fun bar() = 2