[FIR] Implement IMPLICIT_NOTHING_*_TYPE diagnostics

This commit is contained in:
Dmitriy Novozhilov
2022-11-09 18:44:57 +02:00
committed by Space Team
parent 0e84bf2053
commit 1b42298025
18 changed files with 104 additions and 23 deletions
@@ -136,7 +136,7 @@ fun blockNoReturnIfUnitInOneBranch(): Int {
fun nonBlockReturnIfEmptyIf(): Int = <!RETURN_TYPE_MISMATCH!>if (1 < 2) {} else {}<!>
fun nonBlockNoReturnIfUnitInOneBranch(): Int = <!RETURN_TYPE_MISMATCH!>if (1 < 2) {} else 2<!>
val a = <!RETURN_NOT_ALLOWED!>return<!> 1
val <!IMPLICIT_NOTHING_PROPERTY_TYPE!>a<!> = <!RETURN_NOT_ALLOWED!>return<!> 1
class A() {
}
@@ -30,13 +30,13 @@ fun testReturnFromAnonFun() =
return <!RETURN_TYPE_MISMATCH!>if (true) 42 else println()<!>
})
fun testReturn1() =
fun <!IMPLICIT_NOTHING_RETURN_TYPE!>testReturn1<!>() =
run {
return <!RETURN_TYPE_MISMATCH!>if (true) 42
else println()<!>
}
fun testReturn2() =
fun <!IMPLICIT_NOTHING_RETURN_TYPE!>testReturn2<!>() =
run {
return <!RETURN_TYPE_MISMATCH!>if (true) 42
else if (true) 42
@@ -1,10 +1,10 @@
// !DIAGNOSTICS: -UNUSED_EXPRESSION -UNREACHABLE_CODE -UNUSED_PARAMETER -RETURN_NOT_ALLOWED
fun test1() = run {
fun <!IMPLICIT_NOTHING_RETURN_TYPE!>test1<!>() = run {
return <!RETURN_TYPE_MISMATCH!>"OK"<!>
}
fun test2() = run {
fun <!IMPLICIT_NOTHING_RETURN_TYPE!>test2<!>() = run {
fun local(): String {
return ""
}
@@ -14,7 +14,7 @@ fun test() {
val a : Nothing = <!RETURN_NOT_ALLOWED!>return<!> 1
val b = <!RETURN_NOT_ALLOWED!>return<!> 1
val <!IMPLICIT_NOTHING_PROPERTY_TYPE!>b<!> = <!RETURN_NOT_ALLOWED!>return<!> 1
val c = doSmth(if (true) 3 else <!RETURN_NOT_ALLOWED!>return<!>)
@@ -24,7 +24,7 @@ fun testResultOfLambda2() =
}
}
fun testReturn1() =
fun <!IMPLICIT_NOTHING_RETURN_TYPE!>testReturn1<!>() =
run {
return <!RETURN_TYPE_MISMATCH!>when {
true -> 42
@@ -32,7 +32,7 @@ fun testReturn1() =
}<!>
}
fun testReturn2() =
fun <!IMPLICIT_NOTHING_RETURN_TYPE!>testReturn2<!>() =
run {
return <!RETURN_TYPE_MISMATCH!>when {
true -> 42
@@ -80,4 +80,4 @@ val testUsage5: Any get() =
when {
true -> 42
else -> println()
}
}
+10 -10
View File
@@ -1,37 +1,37 @@
fun foo() = throw Exception()
fun <!IMPLICIT_NOTHING_RETURN_TYPE!>foo<!>() = throw Exception()
fun bar() = null!!
fun <!IMPLICIT_NOTHING_RETURN_TYPE!>bar<!>() = null!!
fun baz() = bar()
fun <!IMPLICIT_NOTHING_RETURN_TYPE!>baz<!>() = bar()
fun gav(): Any = null!!
val x = null!!
val <!IMPLICIT_NOTHING_PROPERTY_TYPE!>x<!> = null!!
val y: Nothing = throw Exception()
fun check() {
// Error: KT-10449
fun local() = bar()
fun <!IMPLICIT_NOTHING_RETURN_TYPE!>local<!>() = bar()
// Unreachable / unused, but not implicit Nothing
val x = null!!
}
fun nonLocalReturn() = run { <!RETURN_TYPE_MISMATCH!>return<!> }
fun <!IMPLICIT_NOTHING_RETURN_TYPE!>nonLocalReturn<!>() = run { <!RETURN_TYPE_MISMATCH!>return<!> }
class Klass {
fun bar() = null!!
fun <!IMPLICIT_NOTHING_RETURN_TYPE!>bar<!>() = null!!
val y = null!!
val <!IMPLICIT_NOTHING_PROPERTY_TYPE!>y<!> = null!!
init {
fun local() = bar()
fun <!IMPLICIT_NOTHING_RETURN_TYPE!>local<!>() = bar()
// Should be unreachable: see KT-5311
val z = null!!
}
fun foo() {
fun local() = bar()
fun <!IMPLICIT_NOTHING_RETURN_TYPE!>local<!>() = bar()
val x = y
}
@@ -1,6 +1,6 @@
// !CHECK_TYPE
val x get() = null
val y get() = null!!
val <!IMPLICIT_NOTHING_PROPERTY_TYPE!>y<!> get() = null!!
fun foo() {
x checkType { _<Nothing?>() }