[FIR] Forbid generic type checks inside contracts in K2 as it is done in K1.

#KT-59922
This commit is contained in:
Evgeniy.Zhelenskiy
2023-11-21 15:33:51 +01:00
committed by Space Team
parent a35191706f
commit 5096fd266e
4 changed files with 11 additions and 11 deletions
@@ -13,14 +13,14 @@ inline fun <reified T> referToReifiedGeneric(x: Any?) {
class Generic<T> {
fun referToCaptured(x: Any?) {
contract {
<!ERROR_IN_CONTRACT_DESCRIPTION!>returns() implies (x is T)<!>
<!ERROR_IN_CONTRACT_DESCRIPTION!>returns() implies (x is <!CANNOT_CHECK_FOR_ERASED!>T<!>)<!>
}
}
}
fun referToSubstituted(x: Any?) {
contract {
returns() implies (x is Generic<String>)
returns() implies (x is <!CANNOT_CHECK_FOR_ERASED!>Generic<String><!>)
}
}
@@ -36,13 +36,13 @@ typealias SimpleType = Int
fun referToAliasedGeneric(x: Any?) {
contract {
returns() implies (x is GenericString)
returns() implies (x is <!CANNOT_CHECK_FOR_ERASED!>GenericString<!>)
}
}
fun referToAliasedFunctionType(x: Any?) {
contract {
returns() implies (x is FunctionalType)
returns() implies (x is <!CANNOT_CHECK_FOR_ERASED!>FunctionalType<!>)
}
}
@@ -13,14 +13,14 @@ inline fun <reified T> referToReifiedGeneric(x: Any?) {
class Generic<T> {
fun referToCaptured(x: Any?) {
contract {
<!ERROR_IN_CONTRACT_DESCRIPTION!>returns() implies (x is T)<!>
<!ERROR_IN_CONTRACT_DESCRIPTION!>returns() implies (x is <!CANNOT_CHECK_FOR_ERASED!>T<!>)<!>
}
}
}
fun referToSubstituted(x: Any?) {
contract {
returns() implies (x is Generic<String>)
returns() implies (x is <!CANNOT_CHECK_FOR_ERASED!>Generic<String><!>)
}
}
@@ -36,13 +36,13 @@ typealias SimpleType = Int
fun referToAliasedGeneric(x: Any?) {
contract {
returns() implies (x is GenericString)
returns() implies (x is <!CANNOT_CHECK_FOR_ERASED!>GenericString<!>)
}
}
fun referToAliasedFunctionType(x: Any?) {
contract {
returns() implies (x is FunctionalType)
returns() implies (x is <!CANNOT_CHECK_FOR_ERASED!>FunctionalType<!>)
}
}
@@ -12,13 +12,13 @@ abstract class Base<T> {
@OptIn(ExperimentalContracts::class)
fun checkIsT(s: Any?): Boolean {
contract { <!ERROR_IN_CONTRACT_DESCRIPTION!>returns(true) implies (s is T)<!> }
contract { <!ERROR_IN_CONTRACT_DESCRIPTION!>returns(true) implies (s is <!CANNOT_CHECK_FOR_ERASED!>T<!>)<!> }
return false
}
@OptIn(ExperimentalContracts::class)
fun <R> checkIsOwnerR(s: Any?): Boolean {
contract { <!ERROR_IN_CONTRACT_DESCRIPTION!>returns(true) implies (s is R)<!> }
contract { <!ERROR_IN_CONTRACT_DESCRIPTION!>returns(true) implies (s is <!CANNOT_CHECK_FOR_ERASED!>R<!>)<!> }
return false
}