Do not report IMPLICIT_CAST_TO_ANY on last statement of lambda with Unit(?) in at least one branch.
This commit is contained in:
+61
@@ -0,0 +1,61 @@
|
||||
// !DIAGNOSTICS: -UNUSED_PARAMETER -UNUSED_VARIABLE
|
||||
|
||||
fun println() {}
|
||||
fun foo(x: Any) {}
|
||||
fun <T> fooGeneric(x: T) {}
|
||||
|
||||
fun testResultOfLambda1() =
|
||||
run {
|
||||
if (true) 42 else println()
|
||||
}
|
||||
|
||||
fun testResultOfLambda2() =
|
||||
run {
|
||||
if (true) 42 else if (true) 42 else println()
|
||||
}
|
||||
|
||||
fun testResultOfAnonFun1() =
|
||||
run(fun () =
|
||||
if (true) <!IMPLICIT_CAST_TO_ANY!>42<!>
|
||||
else <!IMPLICIT_CAST_TO_ANY!>println()<!>
|
||||
)
|
||||
|
||||
fun testResultOfAnonFun2() =
|
||||
run(fun () {
|
||||
if (true) <!UNUSED_EXPRESSION!>42<!> else println()
|
||||
})
|
||||
|
||||
fun testReturnFromAnonFun() =
|
||||
run(fun () {
|
||||
return if (true) <!CONSTANT_EXPECTED_TYPE_MISMATCH!>42<!> else println()
|
||||
})
|
||||
|
||||
fun <!IMPLICIT_NOTHING_RETURN_TYPE!>testReturn1<!>() =
|
||||
run {
|
||||
return if (true) <!IMPLICIT_CAST_TO_ANY!>42<!>
|
||||
else <!IMPLICIT_CAST_TO_ANY!>println()<!>
|
||||
}
|
||||
|
||||
fun <!IMPLICIT_NOTHING_RETURN_TYPE!>testReturn2<!>() =
|
||||
run {
|
||||
return if (true) <!IMPLICIT_CAST_TO_ANY!>42<!>
|
||||
else if (true) <!IMPLICIT_CAST_TO_ANY!>42<!>
|
||||
else <!IMPLICIT_CAST_TO_ANY!>println()<!>
|
||||
}
|
||||
|
||||
fun testUsage1() =
|
||||
if (true) <!IMPLICIT_CAST_TO_ANY!>42<!>
|
||||
else <!IMPLICIT_CAST_TO_ANY!>println()<!>
|
||||
|
||||
fun testUsage2() =
|
||||
foo(if (true) 42 else println())
|
||||
|
||||
fun testUsage2Generic() =
|
||||
fooGeneric(if (true) 42 else println())
|
||||
|
||||
val testUsage3 =
|
||||
if (true) <!IMPLICIT_CAST_TO_ANY!>42<!>
|
||||
else <!IMPLICIT_CAST_TO_ANY!>println()<!>
|
||||
|
||||
val testUsage4: Any get() =
|
||||
if (true) 42 else println()
|
||||
+17
@@ -0,0 +1,17 @@
|
||||
package
|
||||
|
||||
public val testUsage3: kotlin.Any
|
||||
public val testUsage4: kotlin.Any
|
||||
public fun foo(/*0*/ x: kotlin.Any): kotlin.Unit
|
||||
public fun </*0*/ T> fooGeneric(/*0*/ x: T): kotlin.Unit
|
||||
public fun println(): kotlin.Unit
|
||||
public fun testResultOfAnonFun1(): kotlin.Any
|
||||
public fun testResultOfAnonFun2(): kotlin.Unit
|
||||
public fun testResultOfLambda1(): kotlin.Any
|
||||
public fun testResultOfLambda2(): kotlin.Any
|
||||
public fun testReturn1(): kotlin.Nothing
|
||||
public fun testReturn2(): kotlin.Nothing
|
||||
public fun testReturnFromAnonFun(): kotlin.Unit
|
||||
public fun testUsage1(): kotlin.Any
|
||||
public fun testUsage2(): kotlin.Unit
|
||||
public fun testUsage2Generic(): kotlin.Unit
|
||||
+31
@@ -0,0 +1,31 @@
|
||||
// !DIAGNOSTICS: -UNUSED_PARAMETER -UNUSED_VARIABLE
|
||||
|
||||
fun println() {}
|
||||
fun foo(x: Any) {}
|
||||
fun <T> fooGeneric(x: T) {}
|
||||
|
||||
fun testMixedIfAndWhen() =
|
||||
if (true)
|
||||
when {
|
||||
true -> if (true) <!IMPLICIT_CAST_TO_ANY!>42<!>
|
||||
else <!IMPLICIT_CAST_TO_ANY!>1<!>
|
||||
true -> if (true) <!IMPLICIT_CAST_TO_ANY!>42<!>
|
||||
else <!IMPLICIT_CAST_TO_ANY!>println()<!>
|
||||
else -> <!INVALID_IF_AS_EXPRESSION!>if (true) <!IMPLICIT_CAST_TO_ANY!>println()<!><!>
|
||||
}
|
||||
else <!IMPLICIT_CAST_TO_ANY!>println()<!>
|
||||
|
||||
fun testWrappedExpressions() =
|
||||
if (true) {
|
||||
println()
|
||||
<!INVALID_IF_AS_EXPRESSION!>if (true) {
|
||||
println()
|
||||
if (true) {
|
||||
<!IMPLICIT_CAST_TO_ANY!>println()<!>
|
||||
}
|
||||
else <!IMPLICIT_CAST_TO_ANY!>{}<!>
|
||||
}<!>
|
||||
}
|
||||
else {
|
||||
(((<!IMPLICIT_CAST_TO_ANY!>((42)) + 1<!>)))
|
||||
}
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
package
|
||||
|
||||
public fun foo(/*0*/ x: kotlin.Any): kotlin.Unit
|
||||
public fun </*0*/ T> fooGeneric(/*0*/ x: T): kotlin.Unit
|
||||
public fun println(): kotlin.Unit
|
||||
public fun testMixedIfAndWhen(): kotlin.Any
|
||||
public fun testWrappedExpressions(): kotlin.Any
|
||||
+2
-2
@@ -17,12 +17,12 @@ fun example() {
|
||||
}();
|
||||
|
||||
{
|
||||
if (true) <!IMPLICIT_CAST_TO_ANY!>{}<!> else <!IMPLICIT_CAST_TO_ANY!>false<!>
|
||||
if (true) {} else false
|
||||
}();
|
||||
|
||||
|
||||
{
|
||||
if (true) <!IMPLICIT_CAST_TO_ANY!>true<!> else <!IMPLICIT_CAST_TO_ANY!>{}<!>
|
||||
if (true) true else {}
|
||||
}()
|
||||
|
||||
fun t(): Boolean {
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
fun test1() {
|
||||
run {
|
||||
if (true) {
|
||||
<!INVALID_IF_AS_EXPRESSION, IMPLICIT_CAST_TO_ANY!>if (true) {}<!>
|
||||
<!INVALID_IF_AS_EXPRESSION!>if (true) {}<!>
|
||||
}
|
||||
else {
|
||||
<!IMPLICIT_CAST_TO_ANY!>1<!>
|
||||
1
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+4
-4
@@ -20,10 +20,10 @@ fun foo() {
|
||||
var <!ASSIGNED_BUT_NEVER_ACCESSED_VARIABLE!>z<!> = 2
|
||||
val r = { // type fun(): Any is inferred
|
||||
if (true) {
|
||||
<!IMPLICIT_CAST_TO_ANY!>2<!>
|
||||
2
|
||||
}
|
||||
else {
|
||||
<!IMPLICIT_CAST_TO_ANY!>z = 34<!>
|
||||
z = 34
|
||||
}
|
||||
}
|
||||
val <!UNUSED_VARIABLE!>f<!>: ()-> Int = <!TYPE_MISMATCH!>r<!>
|
||||
@@ -74,9 +74,9 @@ fun testCoercionToUnit() {
|
||||
var <!ASSIGNED_BUT_NEVER_ACCESSED_VARIABLE!>x<!> = 43
|
||||
val checkType = {
|
||||
if (true) {
|
||||
<!IMPLICIT_CAST_TO_ANY!>x = 4<!>
|
||||
x = 4
|
||||
} else {
|
||||
<!IMPLICIT_CAST_TO_ANY!>45<!>
|
||||
45
|
||||
}
|
||||
}
|
||||
val <!UNUSED_VARIABLE!>f<!> : () -> String = <!TYPE_MISMATCH!>checkType<!>
|
||||
|
||||
+83
@@ -0,0 +1,83 @@
|
||||
// !DIAGNOSTICS: -UNUSED_PARAMETER -UNUSED_VARIABLE
|
||||
|
||||
fun println() {}
|
||||
fun foo(x: Any) {}
|
||||
fun <T> fooGeneric(x: T) {}
|
||||
|
||||
fun testResultOfLambda1() =
|
||||
run {
|
||||
when {
|
||||
true -> 42
|
||||
else -> println()
|
||||
}
|
||||
}
|
||||
|
||||
fun testResultOfLambda2() =
|
||||
run {
|
||||
when {
|
||||
true -> 42
|
||||
else ->
|
||||
when {
|
||||
true -> 42
|
||||
else -> println()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun <!IMPLICIT_NOTHING_RETURN_TYPE!>testReturn1<!>() =
|
||||
run {
|
||||
return when {
|
||||
true -> <!IMPLICIT_CAST_TO_ANY!>42<!>
|
||||
else -> <!IMPLICIT_CAST_TO_ANY!>println()<!>
|
||||
}
|
||||
}
|
||||
|
||||
fun <!IMPLICIT_NOTHING_RETURN_TYPE!>testReturn2<!>() =
|
||||
run {
|
||||
return when {
|
||||
true -> <!IMPLICIT_CAST_TO_ANY!>42<!>
|
||||
else ->
|
||||
when {
|
||||
true -> <!IMPLICIT_CAST_TO_ANY!>42<!>
|
||||
else -> <!IMPLICIT_CAST_TO_ANY!>println()<!>
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun testUsage1() =
|
||||
when {
|
||||
true -> <!IMPLICIT_CAST_TO_ANY!>42<!>
|
||||
else -> <!IMPLICIT_CAST_TO_ANY!>println()<!>
|
||||
}
|
||||
|
||||
fun testUsage2() =
|
||||
foo(when {
|
||||
true -> 42
|
||||
else -> println()
|
||||
})
|
||||
|
||||
fun testUsage2Generic() =
|
||||
fooGeneric(when {
|
||||
true -> 42
|
||||
else -> println()
|
||||
})
|
||||
|
||||
val testUsage3 =
|
||||
when {
|
||||
true -> <!IMPLICIT_CAST_TO_ANY!>42<!>
|
||||
else -> <!IMPLICIT_CAST_TO_ANY!>println()<!>
|
||||
}
|
||||
|
||||
val testUsage4 =
|
||||
when {
|
||||
true -> <!IMPLICIT_CAST_TO_ANY!>42<!>
|
||||
true -> <!IMPLICIT_CAST_TO_ANY!>42<!>
|
||||
true -> <!IMPLICIT_CAST_TO_ANY!>42<!>
|
||||
else -> <!IMPLICIT_CAST_TO_ANY!>println()<!>
|
||||
}
|
||||
|
||||
val testUsage5: Any get() =
|
||||
when {
|
||||
true -> 42
|
||||
else -> println()
|
||||
}
|
||||
+15
@@ -0,0 +1,15 @@
|
||||
package
|
||||
|
||||
public val testUsage3: kotlin.Any
|
||||
public val testUsage4: kotlin.Any
|
||||
public val testUsage5: kotlin.Any
|
||||
public fun foo(/*0*/ x: kotlin.Any): kotlin.Unit
|
||||
public fun </*0*/ T> fooGeneric(/*0*/ x: T): kotlin.Unit
|
||||
public fun println(): kotlin.Unit
|
||||
public fun testResultOfLambda1(): kotlin.Any
|
||||
public fun testResultOfLambda2(): kotlin.Any
|
||||
public fun testReturn1(): kotlin.Nothing
|
||||
public fun testReturn2(): kotlin.Nothing
|
||||
public fun testUsage1(): kotlin.Any
|
||||
public fun testUsage2(): kotlin.Unit
|
||||
public fun testUsage2Generic(): kotlin.Unit
|
||||
Reference in New Issue
Block a user