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
|
||||
}
|
||||
+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 {
|
||||
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)
|
||||
<!DEBUG_INFO_SMARTCAST!>x<!>.length
|
||||
}
|
||||
|
||||
fun test_2(foo: Foo): Int {
|
||||
val x: Int
|
||||
foo.myRun {
|
||||
x = 1
|
||||
}
|
||||
return x + 1
|
||||
}
|
||||
+17
@@ -0,0 +1,17 @@
|
||||
package
|
||||
|
||||
public fun test_1(/*0*/ foo: Foo, /*1*/ x: kotlin.Any): kotlin.Unit
|
||||
public fun test_2(/*0*/ foo: Foo): kotlin.Int
|
||||
|
||||
public final class Foo {
|
||||
public constructor Foo()
|
||||
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 fun myRun(/*0*/ block: () -> kotlin.Unit): kotlin.Unit
|
||||
CallsInPlace(block, EXACTLY_ONCE)
|
||||
|
||||
public final fun require(/*0*/ x: kotlin.Boolean): kotlin.Unit
|
||||
Returns(WILDCARD) -> x
|
||||
|
||||
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
||||
}
|
||||
Reference in New Issue
Block a user