Allow contracts on final non-override members since 1.4
This commit is contained in:
Vendored
+31
@@ -0,0 +1,31 @@
|
||||
// !LANGUAGE: +AllowContractsForCustomFunctions +UseReturnsEffect +AllowContractsForNonOverridableMembers
|
||||
// !USE_EXPERIMENTAL: kotlin.contracts.ExperimentalContracts
|
||||
// !DIAGNOSTICS: -INVISIBLE_REFERENCE -INVISIBLE_MEMBER
|
||||
|
||||
import kotlin.contracts.*
|
||||
|
||||
class Foo {
|
||||
fun myRun(block: () -> Unit) {
|
||||
contract {
|
||||
<!INAPPLICABLE_CANDIDATE!>callsInPlace<!>(block, InvocationKind.EXACTLY_ONCE)
|
||||
}
|
||||
block()
|
||||
}
|
||||
|
||||
fun require(x: Boolean) {
|
||||
contract { returns() implies (x) }
|
||||
}
|
||||
}
|
||||
|
||||
fun test_1(foo: Foo, x: Any) {
|
||||
foo.require(x is String)
|
||||
x.<!UNRESOLVED_REFERENCE!>length<!>
|
||||
}
|
||||
|
||||
fun test_2(foo: Foo): Int {
|
||||
val x: Int
|
||||
foo.myRun {
|
||||
x = 1
|
||||
}
|
||||
return x + 1
|
||||
}
|
||||
Reference in New Issue
Block a user