Add few tests for contracts

- Contracts in getter/setter (unexpected behaviour)
- Check smartcasts when non-null assertion for a contract function is used
- Check work of contracts when type parameter of the callsInPlace is specify explicitly
- Check smartcasts working if type checking for contract function is used
This commit is contained in:
victor.petukhov
2018-09-25 12:21:42 +03:00
parent ecb3f10e47
commit 8538866778
9 changed files with 484 additions and 5 deletions
@@ -0,0 +1,52 @@
// !LANGUAGE: +AllowContractsForCustomFunctions +UseCallsInPlaceEffect
// !USE_EXPERIMENTAL: kotlin.contracts.ExperimentalContracts
/*
KOTLIN DIAGNOSTICS NOT LINKED SPEC TEST (POSITIVE)
SECTION: contracts
CATEGORIES: analysis, controlFlow, initialization
NUMBER: 7
DESCRIPTION: Check initialization when type parameter of the callsInPlace is specify explicitly.
*/
// FILE: contracts.kt
package contracts
import kotlin.contracts.*
inline fun <T> case_1(block: () -> T): T {
contract {
callsInPlace<T>(block, InvocationKind.EXACTLY_ONCE)
}
return block()
}
inline fun case_2(block: () -> Int): Int {
contract {
callsInPlace<Number>(block, InvocationKind.EXACTLY_ONCE)
}
return block()
}
// FILE: usages.kt
import contracts.*
fun case_1() {
val value_1: Int
case_1 {
value_1 = 10
}
println(value_1)
}
fun case_2() {
val value_1: Int
case_2 {
value_1 = 10
10
}
println(value_1)
}
@@ -0,0 +1,13 @@
package
public fun case_1(): kotlin.Unit
public fun case_2(): kotlin.Unit
package contracts {
public inline fun </*0*/ T> case_1(/*0*/ block: () -> T): T
CallsInPlace(block, EXACTLY_ONCE)
public inline fun case_2(/*0*/ block: () -> kotlin.Int): kotlin.Int
CallsInPlace(block, EXACTLY_ONCE)
}