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:
Vendored
+64
@@ -0,0 +1,64 @@
|
||||
// !LANGUAGE: +AllowContractsForCustomFunctions +UseCallsInPlaceEffect
|
||||
// !DIAGNOSTICS: -INVISIBLE_REFERENCE -INVISIBLE_MEMBER -UNUSED_PARAMETER
|
||||
// !USE_EXPERIMENTAL: kotlin.contracts.ExperimentalContracts
|
||||
|
||||
/*
|
||||
KOTLIN DIAGNOSTICS NOT LINKED SPEC TEST (NEGATIVE)
|
||||
|
||||
SECTION: contracts
|
||||
CATEGORIES: declarations, contractFunction
|
||||
NUMBER: 4
|
||||
DESCRIPTION: Check that fun with contract and CallsInPlace effect is an inline function.
|
||||
UNEXPECTED BEHAVIOUR
|
||||
ISSUES: KT-27090
|
||||
*/
|
||||
|
||||
import kotlin.contracts.*
|
||||
|
||||
val Boolean.case_1: () -> Unit
|
||||
get() {
|
||||
contract {
|
||||
returns() implies (this@case_1)
|
||||
}
|
||||
return {}
|
||||
}
|
||||
|
||||
val (() -> Unit).case_2: () -> Unit
|
||||
get() {
|
||||
contract {
|
||||
callsInPlace(this@case_2, InvocationKind.EXACTLY_ONCE)
|
||||
}
|
||||
return {}
|
||||
}
|
||||
|
||||
var Boolean.case_3: () -> Unit
|
||||
get() {
|
||||
return {}
|
||||
}
|
||||
set(value) {
|
||||
contract {
|
||||
callsInPlace(value, InvocationKind.EXACTLY_ONCE)
|
||||
}
|
||||
}
|
||||
|
||||
var (() -> Unit).case_4: () -> Unit
|
||||
get() {
|
||||
return {}
|
||||
}
|
||||
set(value) {
|
||||
contract {
|
||||
callsInPlace(this@case_4, InvocationKind.EXACTLY_ONCE)
|
||||
}
|
||||
}
|
||||
|
||||
val Boolean.case_5: () -> Unit
|
||||
get() {
|
||||
contract {
|
||||
returns() implies (this@case_5)
|
||||
}
|
||||
|
||||
if (!this@case_5)
|
||||
throw Exception()
|
||||
|
||||
return {}
|
||||
}
|
||||
compiler/tests-spec/testData/diagnostics/notLinked/contracts/declarations/contractFunction/neg/4.txt
Vendored
+7
@@ -0,0 +1,7 @@
|
||||
package
|
||||
|
||||
public val kotlin.Boolean.case_1: () -> kotlin.Unit
|
||||
public val (() -> kotlin.Unit).case_2: () -> kotlin.Unit
|
||||
public var kotlin.Boolean.case_3: () -> kotlin.Unit
|
||||
public var (() -> kotlin.Unit).case_4: () -> kotlin.Unit
|
||||
public val kotlin.Boolean.case_5: () -> kotlin.Unit
|
||||
Reference in New Issue
Block a user