[FIR] Move FirReturnsImpliesAnalyzer to the extended checkers

This commit is contained in:
Nikolay Lunyak
2023-06-27 16:57:19 +03:00
committed by Space Team
parent db720d375d
commit 884cd6c754
21 changed files with 67 additions and 120 deletions
@@ -27,9 +27,9 @@ class Foo {
}
fun A?.goodWithReceiver() {
<!WRONG_IMPLIES_CONDITION!>contract {
contract {
returns() implies (this@goodWithReceiver != null)
}<!>
}
}
fun A?.badWithReceiver() {
@@ -48,8 +48,8 @@ fun doWhileInContract(x: Any?) {
}
fun localValInContract(x: Any?) {
<!WRONG_IMPLIES_CONDITION!>contract {
contract {
<!ERROR_IN_CONTRACT_DESCRIPTION!>val y: Int = 42<!>
returns() implies (x is String)
}<!>
}
}
@@ -5,9 +5,9 @@
import kotlin.contracts.*
inline fun <reified T> referToReifiedGeneric(x: Any?) {
<!WRONG_IMPLIES_CONDITION!>contract {
contract {
returns() implies (x is T)
}<!>
}
}
class Generic<T> {
@@ -19,15 +19,15 @@ class Generic<T> {
}
fun referToSubstituted(x: Any?) {
<!WRONG_IMPLIES_CONDITION!>contract {
contract {
returns() implies (x is Generic<String>)
}<!>
}
}
fun referToSubstitutedWithStar(x: Any?) {
<!WRONG_IMPLIES_CONDITION!>contract {
contract {
returns() implies (x is Generic<*>)
}<!>
}
}
typealias GenericString = Generic<String>
@@ -35,19 +35,19 @@ typealias FunctionalType = () -> Unit
typealias SimpleType = Int
fun referToAliasedGeneric(x: Any?) {
<!WRONG_IMPLIES_CONDITION!>contract {
contract {
returns() implies (x is GenericString)
}<!>
}
}
fun referToAliasedFunctionType(x: Any?) {
<!WRONG_IMPLIES_CONDITION!>contract {
contract {
returns() implies (x is FunctionalType)
}<!>
}
}
fun referToAliasedSimpleType(x: Any?) {
<!WRONG_IMPLIES_CONDITION!>contract {
contract {
returns() implies (x is SimpleType)
}<!>
}
}
@@ -5,9 +5,9 @@
import kotlin.contracts.*
inline fun <reified T> referToReifiedGeneric(x: Any?) {
<!WRONG_IMPLIES_CONDITION!>contract {
contract {
returns() implies (x is T)
}<!>
}
}
class Generic<T> {
@@ -19,15 +19,15 @@ class Generic<T> {
}
fun referToSubstituted(x: Any?) {
<!WRONG_IMPLIES_CONDITION!>contract {
contract {
returns() implies (x is Generic<String>)
}<!>
}
}
fun referToSubstitutedWithStar(x: Any?) {
<!WRONG_IMPLIES_CONDITION!>contract {
contract {
returns() implies (x is Generic<*>)
}<!>
}
}
typealias GenericString = Generic<String>
@@ -35,19 +35,19 @@ typealias FunctionalType = () -> Unit
typealias SimpleType = Int
fun referToAliasedGeneric(x: Any?) {
<!WRONG_IMPLIES_CONDITION!>contract {
contract {
returns() implies (x is GenericString)
}<!>
}
}
fun referToAliasedFunctionType(x: Any?) {
<!WRONG_IMPLIES_CONDITION!>contract {
contract {
returns() implies (x is FunctionalType)
}<!>
}
}
fun referToAliasedSimpleType(x: Any?) {
<!WRONG_IMPLIES_CONDITION!>contract {
contract {
returns() implies (x is SimpleType)
}<!>
}
}
@@ -1,19 +0,0 @@
// ISSUE: KT-45243
import kotlin.contracts.ExperimentalContracts
import kotlin.contracts.contract
@ExperimentalContracts
fun <T> assertNotNull(actual: T) {
<!WRONG_IMPLIES_CONDITION!>contract { returns() implies (actual != null) }<!>
}
@ExperimentalContracts
fun test_1() {
assertNotNull { }
}
@ExperimentalContracts
fun test_2() {
assertNotNull({ })
}
@@ -1,3 +1,4 @@
// FIR_IDENTICAL
// ISSUE: KT-45243
import kotlin.contracts.ExperimentalContracts
@@ -5,7 +5,7 @@ fun calculateNumber(block: () -> Int): Int contract [
callsInPlace(block, InvocationKind.EXACTLY_ONCE)
] = block()
fun <R> calculateResult(num: Int?, calculate: (Int?) -> R): R contract <!WRONG_IMPLIES_CONDITION!>[
fun <R> calculateResult(num: Int?, calculate: (Int?) -> R): R contract [
callsInPlace(calculate, InvocationKind.EXACTLY_ONCE),
returns() implies (num != null)
]<!> = calculate(num)
] = calculate(num)
@@ -17,7 +17,7 @@ open class Foo {
}
inline fun <reified T> assertIs(value: Any) {
<!WRONG_IMPLIES_CONDITION!>contract { returns() implies (value is T) }<!>
contract { returns() implies (value is T) }
}
}
@@ -31,9 +31,9 @@ fun testNullWhenNull(x: Int?) {
// NB. it is the same function as `nullWhenNull`, but annotations specifies other facet of the function behaviour
fun notNullWhenNotNull (x: Int?): Int? {
<!WRONG_IMPLIES_CONDITION!>contract {
contract {
returns(null) implies (x == null)
}<!>
}
return x?.inc()
}
@@ -5,9 +5,9 @@
import kotlin.contracts.*
fun safeIsString(x: Any?): Boolean? {
<!WRONG_IMPLIES_CONDITION!>contract {
contract {
returns(true) implies (x is String)
}<!>
}
return x?.let { it is String }
}
@@ -5,9 +5,9 @@
import kotlin.contracts.*
fun safeIsString(x: Any?): Boolean? {
<!WRONG_IMPLIES_CONDITION!>contract {
contract {
returns(true) implies (x is String)
}<!>
}
return x?.let { it is String }
}