Allow contracts on final non-override members since 1.4

This commit is contained in:
Dmitriy Novozhilov
2019-12-26 11:53:27 +03:00
parent 5a9070b6da
commit f083edfac2
34 changed files with 682 additions and 45 deletions
@@ -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
}