[FIR] Forbid generic type checks inside contracts in K2 as it is done in K1.
#KT-59922
This commit is contained in:
committed by
Space Team
parent
a35191706f
commit
5096fd266e
+1
-1
@@ -48,7 +48,7 @@ object FirCastOperatorsChecker : FirTypeOperatorCallChecker() {
|
||||
reporter.reportOn(expression.source, FirErrors.UNCHECKED_CAST, actualType, targetType, context)
|
||||
}
|
||||
} else if (expression.operation == FirOperation.IS) {
|
||||
if (!context.isContractBody && isCastErased(actualType, targetType, context)) {
|
||||
if (isCastErased(actualType, targetType, context)) {
|
||||
reporter.reportOn(conversionTypeRef.source, FirErrors.CANNOT_CHECK_FOR_ERASED, targetType, context)
|
||||
}
|
||||
}
|
||||
|
||||
Vendored
+4
-4
@@ -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<!>)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Vendored
+4
-4
@@ -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<!>)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Vendored
+2
-2
@@ -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
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user