Allow use reference to reified type parameters in contracts since 1.4
This commit is contained in:
+23
@@ -0,0 +1,23 @@
|
||||
// !LANGUAGE: +AllowContractsForCustomFunctions +ReadDeserializedContracts +AllowContractsForNonOverridableMembers +AllowReifiedGenericsInContracts
|
||||
// !USE_EXPERIMENTAL: kotlin.contracts.ExperimentalContracts
|
||||
@file:Suppress("INVISIBLE_MEMBER", "INVISIBLE_REFERENCE")
|
||||
|
||||
package test
|
||||
|
||||
import kotlin.contracts.*
|
||||
|
||||
inline fun <reified T> requireIsInstance(value: Any?) {
|
||||
contract {
|
||||
returns() implies (value is T)
|
||||
}
|
||||
if (value !is T) {
|
||||
throw IllegalArgumentException()
|
||||
}
|
||||
}
|
||||
|
||||
inline fun <reified T, reified U> cast(value: Any?, z: U): T {
|
||||
contract {
|
||||
returns() implies (value is T)
|
||||
}
|
||||
return value as T
|
||||
}
|
||||
Vendored
+7
@@ -0,0 +1,7 @@
|
||||
package test
|
||||
|
||||
public inline fun </*0*/ reified T, /*1*/ reified U> cast(/*0*/ value: kotlin.Any?, /*1*/ z: U): T
|
||||
Returns(WILDCARD) -> value is T
|
||||
|
||||
public inline fun </*0*/ reified T> requireIsInstance(/*0*/ value: kotlin.Any?): kotlin.Unit
|
||||
Returns(WILDCARD) -> value is T
|
||||
Reference in New Issue
Block a user