[FIR] Use argument mapping from resolved call for contract argument mapping

This commit is contained in:
Dmitriy Novozhilov
2020-04-14 12:33:33 +03:00
parent 5b660d2457
commit c71f9d9640
4 changed files with 71 additions and 7 deletions
@@ -0,0 +1,29 @@
import kotlin.contracts.*
fun foo(x: Any, y: Any) {
contract {
returns() implies (x is Int && y is String)
}
if (x !is Int || y !is String) {
throw IllegalStateException()
}
}
fun test_1(x: Any, y: Any) {
foo(x = x, y = y)
x.inc()
y.length
}
fun test_2(x: Any, y: Any) {
foo(x, y = y)
x.inc()
y.length
}
fun test_3(x: Any, y: Any) {
foo(y = y, x = x)
x.inc()
y.length
}
@@ -0,0 +1,30 @@
FILE: namedArguments.kt
public final fun foo(x: R|kotlin/Any|, y: R|kotlin/Any|): R|kotlin/Unit|
[R|Contract description]
<
Returns(WILDCARD) -> x is kotlin/Int && y is kotlin/String
>
{
[StubStatement]
when () {
(R|<local>/x| !is R|kotlin/Int|) || (R|<local>/y| !is R|kotlin/String|) -> {
throw R|java/lang/IllegalStateException.IllegalStateException|()
}
}
}
public final fun test_1(x: R|kotlin/Any|, y: R|kotlin/Any|): R|kotlin/Unit| {
R|/foo|(x = R|<local>/x|, y = R|<local>/y|)
R|<local>/x|.R|kotlin/Int.inc|()
R|<local>/y|.R|kotlin/String.length|
}
public final fun test_2(x: R|kotlin/Any|, y: R|kotlin/Any|): R|kotlin/Unit| {
R|/foo|(R|<local>/x|, y = R|<local>/y|)
R|<local>/x|.R|kotlin/Int.inc|()
R|<local>/y|.R|kotlin/String.length|
}
public final fun test_3(x: R|kotlin/Any|, y: R|kotlin/Any|): R|kotlin/Unit| {
R|/foo|(y = R|<local>/y|, x = R|<local>/x|)
R|<local>/x|.R|kotlin/Int.inc|()
R|<local>/y|.R|kotlin/String.length|
}