[Test] Add test for KT-48115

This commit is contained in:
Dmitriy Novozhilov
2023-07-03 12:40:19 +03:00
committed by Space Team
parent ca25610756
commit 637b46cb6e
3 changed files with 96 additions and 14 deletions
@@ -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 <reified T> assertIs(value: Any) {
<!WRONG_IMPLIES_CONDITION!>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<String>(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<String>(x)
x.length
}
fun test_3(foo: Foo): Int {
val x: Int
foo.myRun {
x = 1
@@ -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 <reified T> assertIs(value: Any) {
contract { returns() implies (value is T) }
}
}
class Bar : Foo() {
fun test_1(x: Any) {
myRequire(x is String)
<!DEBUG_INFO_SMARTCAST!>x<!>.length
}
fun test_2(x: Any) {
assertIs<String>(x)
x.<!UNRESOLVED_REFERENCE!>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)
<!DEBUG_INFO_SMARTCAST!>x<!>.length
}
fun test_2(foo: Foo): Int {
fun test_2(foo: Foo, x: Any) {
foo.assertIs<String>(x)
<!DEBUG_INFO_SMARTCAST!>x<!>.length
}
fun test_3(foo: Foo): Int {
val x: Int
foo.myRun {
x = 1
@@ -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 </*0*/ reified T> 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 </*0*/ reified T> 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
}