diff --git a/compiler/testData/diagnostics/testsWithStdLib/contracts/smartcasts/contractsOnMembers.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/contracts/smartcasts/contractsOnMembers.fir.kt index 366aee5408e..1a38660d1ca 100644 --- a/compiler/testData/diagnostics/testsWithStdLib/contracts/smartcasts/contractsOnMembers.fir.kt +++ b/compiler/testData/diagnostics/testsWithStdLib/contracts/smartcasts/contractsOnMembers.fir.kt @@ -4,7 +4,7 @@ import kotlin.contracts.* -class Foo { +open class Foo { fun myRun(block: () -> Unit) { contract { callsInPlace(block, InvocationKind.EXACTLY_ONCE) @@ -12,17 +12,46 @@ class Foo { block() } - fun require(x: Boolean) { + fun myRequire(x: Boolean) { contract { returns() implies (x) } } + + inline fun assertIs(value: Any) { + contract { returns() implies (value is T) } + } +} + +class Bar : Foo() { + fun test_1(x: Any) { + myRequire(x is String) + x.length + } + + fun test_2(x: Any) { + assertIs(x) + x.length + } + + fun test_3(): Int { + val x: Int + myRun { + x = 1 + } + return x + 1 + } } fun test_1(foo: Foo, x: Any) { - foo.require(x is String) + foo.myRequire(x is String) x.length } -fun test_2(foo: Foo): Int { +fun test_2(foo: Foo, x: Any) { + foo.assertIs(x) + x.length +} + +fun test_3(foo: Foo): Int { val x: Int foo.myRun { x = 1 diff --git a/compiler/testData/diagnostics/testsWithStdLib/contracts/smartcasts/contractsOnMembers.kt b/compiler/testData/diagnostics/testsWithStdLib/contracts/smartcasts/contractsOnMembers.kt index 520a8571f8c..f5563df584f 100644 --- a/compiler/testData/diagnostics/testsWithStdLib/contracts/smartcasts/contractsOnMembers.kt +++ b/compiler/testData/diagnostics/testsWithStdLib/contracts/smartcasts/contractsOnMembers.kt @@ -4,7 +4,7 @@ import kotlin.contracts.* -class Foo { +open class Foo { fun myRun(block: () -> Unit) { contract { callsInPlace(block, InvocationKind.EXACTLY_ONCE) @@ -12,17 +12,46 @@ class Foo { block() } - fun require(x: Boolean) { + fun myRequire(x: Boolean) { contract { returns() implies (x) } } + + inline fun assertIs(value: Any) { + contract { returns() implies (value is T) } + } +} + +class Bar : Foo() { + fun test_1(x: Any) { + myRequire(x is String) + x.length + } + + fun test_2(x: Any) { + assertIs(x) + x.length + } + + fun test_3(): Int { + val x: Int + myRun { + x = 1 + } + return x + 1 + } } fun test_1(foo: Foo, x: Any) { - foo.require(x is String) + foo.myRequire(x is String) x.length } -fun test_2(foo: Foo): Int { +fun test_2(foo: Foo, x: Any) { + foo.assertIs(x) + x.length +} + +fun test_3(foo: Foo): Int { val x: Int foo.myRun { x = 1 diff --git a/compiler/testData/diagnostics/testsWithStdLib/contracts/smartcasts/contractsOnMembers.txt b/compiler/testData/diagnostics/testsWithStdLib/contracts/smartcasts/contractsOnMembers.txt index 2a7eb3c2ea9..f8144d90e8d 100644 --- a/compiler/testData/diagnostics/testsWithStdLib/contracts/smartcasts/contractsOnMembers.txt +++ b/compiler/testData/diagnostics/testsWithStdLib/contracts/smartcasts/contractsOnMembers.txt @@ -1,17 +1,41 @@ package public fun test_1(/*0*/ foo: Foo, /*1*/ x: kotlin.Any): kotlin.Unit -public fun test_2(/*0*/ foo: Foo): kotlin.Int +public fun test_2(/*0*/ foo: Foo, /*1*/ x: kotlin.Any): kotlin.Unit +public fun test_3(/*0*/ foo: Foo): kotlin.Int + +public final class Bar : Foo { + public constructor Bar() + public final override /*1*/ inline /*fake_override*/ fun assertIs(/*0*/ value: kotlin.Any): kotlin.Unit + Returns(WILDCARD) -> value is T -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 override /*1*/ /*fake_override*/ fun myRequire(/*0*/ x: kotlin.Boolean): kotlin.Unit + Returns(WILDCARD) -> x + + public final override /*1*/ /*fake_override*/ fun myRun(/*0*/ block: () -> kotlin.Unit): kotlin.Unit + CallsInPlace(block, EXACTLY_ONCE) + + public final fun test_1(/*0*/ x: kotlin.Any): kotlin.Unit + public final fun test_2(/*0*/ x: kotlin.Any): kotlin.Unit + public final fun test_3(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} + +public open class Foo { + public constructor Foo() + public final inline fun assertIs(/*0*/ value: kotlin.Any): kotlin.Unit + Returns(WILDCARD) -> value is T + + 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 myRequire(/*0*/ x: kotlin.Boolean): kotlin.Unit + Returns(WILDCARD) -> x + 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 } +