Allow use reference to reified type parameters in contracts since 1.4
This commit is contained in:
Vendored
+1
-1
@@ -1,4 +1,4 @@
|
||||
// !LANGUAGE: +AllowContractsForCustomFunctions +UseReturnsEffect +AllowContractsForNonOverridableMembers
|
||||
// !LANGUAGE: +AllowContractsForCustomFunctions +UseReturnsEffect +AllowContractsForNonOverridableMembers +AllowReifiedGenericsInContracts
|
||||
// !USE_EXPERIMENTAL: kotlin.contracts.ExperimentalContracts
|
||||
// !DIAGNOSTICS: -INVISIBLE_REFERENCE -INVISIBLE_MEMBER -NOTHING_TO_INLINE -ABSTRACT_FUNCTION_IN_NON_ABSTRACT_CLASS -ABSTRACT_FUNCTION_WITH_BODY -UNUSED_PARAMETER -UNUSED_VARIABLE -EXPERIMENTAL_FEATURE_WARNING
|
||||
|
||||
|
||||
Vendored
+1
-1
@@ -1,4 +1,4 @@
|
||||
// !LANGUAGE: +AllowContractsForCustomFunctions +UseReturnsEffect +AllowContractsForNonOverridableMembers
|
||||
// !LANGUAGE: +AllowContractsForCustomFunctions +UseReturnsEffect +AllowContractsForNonOverridableMembers +AllowReifiedGenericsInContracts
|
||||
// !USE_EXPERIMENTAL: kotlin.contracts.ExperimentalContracts
|
||||
// !DIAGNOSTICS: -INVISIBLE_REFERENCE -INVISIBLE_MEMBER -NOTHING_TO_INLINE -ABSTRACT_FUNCTION_IN_NON_ABSTRACT_CLASS -ABSTRACT_FUNCTION_WITH_BODY -UNUSED_PARAMETER -UNUSED_VARIABLE -EXPERIMENTAL_FEATURE_WARNING
|
||||
|
||||
|
||||
Vendored
+6
@@ -21,9 +21,15 @@ public open class Class {
|
||||
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
||||
public final inline fun inlineMember(/*0*/ x: kotlin.Boolean): kotlin.Unit
|
||||
Returns(WILDCARD) -> x
|
||||
|
||||
public final fun member(/*0*/ x: kotlin.Boolean): kotlin.Unit
|
||||
Returns(WILDCARD) -> x
|
||||
|
||||
public open fun openMemeber(/*0*/ x: kotlin.Boolean): kotlin.Unit
|
||||
public final suspend fun suspendMember(/*0*/ x: kotlin.Boolean): kotlin.Unit
|
||||
Returns(WILDCARD) -> x
|
||||
|
||||
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
||||
}
|
||||
|
||||
|
||||
Vendored
+1
-1
@@ -1,4 +1,4 @@
|
||||
// !LANGUAGE: +AllowContractsForCustomFunctions +UseReturnsEffect -AllowContractsForNonOverridableMembers
|
||||
// !LANGUAGE: +AllowContractsForCustomFunctions +UseReturnsEffect -AllowContractsForNonOverridableMembers -AllowReifiedGenericsInContracts
|
||||
// !USE_EXPERIMENTAL: kotlin.contracts.ExperimentalContracts
|
||||
// !DIAGNOSTICS: -INVISIBLE_REFERENCE -INVISIBLE_MEMBER
|
||||
|
||||
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
// !LANGUAGE: +AllowContractsForCustomFunctions +UseReturnsEffect -AllowContractsForNonOverridableMembers
|
||||
// !LANGUAGE: +AllowContractsForCustomFunctions +UseReturnsEffect -AllowContractsForNonOverridableMembers -AllowReifiedGenericsInContracts
|
||||
// !USE_EXPERIMENTAL: kotlin.contracts.ExperimentalContracts
|
||||
// !DIAGNOSTICS: -INVISIBLE_REFERENCE -INVISIBLE_MEMBER
|
||||
|
||||
|
||||
Vendored
+1
-1
@@ -1,4 +1,4 @@
|
||||
// !LANGUAGE: +AllowContractsForCustomFunctions +UseReturnsEffect +AllowContractsForNonOverridableMembers
|
||||
// !LANGUAGE: +AllowContractsForCustomFunctions +UseReturnsEffect +AllowContractsForNonOverridableMembers +AllowReifiedGenericsInContracts
|
||||
// !USE_EXPERIMENTAL: kotlin.contracts.ExperimentalContracts
|
||||
// !DIAGNOSTICS: -INVISIBLE_REFERENCE -INVISIBLE_MEMBER
|
||||
|
||||
|
||||
+2
-2
@@ -1,4 +1,4 @@
|
||||
// !LANGUAGE: +AllowContractsForCustomFunctions +UseReturnsEffect +AllowContractsForNonOverridableMembers
|
||||
// !LANGUAGE: +AllowContractsForCustomFunctions +UseReturnsEffect +AllowContractsForNonOverridableMembers +AllowReifiedGenericsInContracts
|
||||
// !USE_EXPERIMENTAL: kotlin.contracts.ExperimentalContracts
|
||||
// !DIAGNOSTICS: -INVISIBLE_REFERENCE -INVISIBLE_MEMBER
|
||||
|
||||
@@ -6,7 +6,7 @@ import kotlin.contracts.*
|
||||
|
||||
inline fun <reified T> referToReifiedGeneric(x: Any?) {
|
||||
contract {
|
||||
returns() implies (x is <!ERROR_IN_CONTRACT_DESCRIPTION("references to type parameters are forbidden in contracts")!>T<!>)
|
||||
returns() implies (x is T)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+2
@@ -6,6 +6,8 @@ public fun referToAliasedSimpleType(/*0*/ x: kotlin.Any?): kotlin.Unit
|
||||
Returns(WILDCARD) -> x is Int
|
||||
|
||||
public inline fun </*0*/ reified T> referToReifiedGeneric(/*0*/ x: kotlin.Any?): kotlin.Unit
|
||||
Returns(WILDCARD) -> x is T
|
||||
|
||||
public fun referToSubstituted(/*0*/ x: kotlin.Any?): kotlin.Unit
|
||||
public fun referToSubstitutedWithStar(/*0*/ x: kotlin.Any?): kotlin.Unit
|
||||
Returns(WILDCARD) -> x is Generic<*>
|
||||
|
||||
+31
@@ -0,0 +1,31 @@
|
||||
// !LANGUAGE: +AllowContractsForCustomFunctions +UseReturnsEffect +AllowReifiedGenericsInContracts
|
||||
// !USE_EXPERIMENTAL: kotlin.contracts.ExperimentalContracts
|
||||
// !DIAGNOSTICS: -INVISIBLE_REFERENCE -INVISIBLE_MEMBER -UNUSED_VARIABLE
|
||||
|
||||
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> cast(value: Any?): T {
|
||||
contract {
|
||||
returns() implies (value is T)
|
||||
}
|
||||
return value as T
|
||||
}
|
||||
|
||||
fun test_1(x: Any) {
|
||||
requireIsInstance<String>(x)
|
||||
x.<!UNRESOLVED_REFERENCE!>length<!>
|
||||
}
|
||||
|
||||
fun test_2(x: Any) {
|
||||
val s: String = cast(x)
|
||||
x.<!UNRESOLVED_REFERENCE!>length<!>
|
||||
}
|
||||
+31
@@ -0,0 +1,31 @@
|
||||
// !LANGUAGE: +AllowContractsForCustomFunctions +UseReturnsEffect +AllowReifiedGenericsInContracts
|
||||
// !USE_EXPERIMENTAL: kotlin.contracts.ExperimentalContracts
|
||||
// !DIAGNOSTICS: -INVISIBLE_REFERENCE -INVISIBLE_MEMBER -UNUSED_VARIABLE
|
||||
|
||||
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> cast(value: Any?): T {
|
||||
contract {
|
||||
returns() implies (value is T)
|
||||
}
|
||||
return value as T
|
||||
}
|
||||
|
||||
fun test_1(x: Any) {
|
||||
requireIsInstance<String>(x)
|
||||
<!DEBUG_INFO_SMARTCAST!>x<!>.length
|
||||
}
|
||||
|
||||
fun test_2(x: Any) {
|
||||
val s: String = cast(x)
|
||||
<!DEBUG_INFO_SMARTCAST!>x<!>.length
|
||||
}
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
package
|
||||
|
||||
public inline fun </*0*/ reified T> cast(/*0*/ value: kotlin.Any?): T
|
||||
Returns(WILDCARD) -> value is T
|
||||
|
||||
public inline fun </*0*/ reified T> requireIsInstance(/*0*/ value: kotlin.Any?): kotlin.Unit
|
||||
Returns(WILDCARD) -> value is T
|
||||
|
||||
public fun test_1(/*0*/ x: kotlin.Any): kotlin.Unit
|
||||
public fun test_2(/*0*/ x: kotlin.Any): kotlin.Unit
|
||||
Reference in New Issue
Block a user