[PSI2IR] Support context receivers on classes

This commit is contained in:
Anastasiya Shadrina
2020-09-04 11:24:28 +07:00
committed by TeamCityServer
parent 307f318c9e
commit aaabf5e1ca
23 changed files with 368 additions and 15 deletions
@@ -0,0 +1,32 @@
// TARGET_BACKEND: JVM_IR
// IGNORE_BACKEND_FIR: JVM_IR
// WITH_RUNTIME
class A(val ok: String)
context(A)
class B(oValue: Boolean = true, kValue: Boolean = true) {
var o: Boolean
var k: Boolean
init {
o = oValue
k = kValue
}
constructor(oValue: String, kValue: String) : this(oValue == "O", kValue == "K")
fun result() = if (o && k) ok else "fail"
}
fun box(): String {
val a = A("OK")
with (a) {
val results = listOf(
B(true, true).result(),
B("O", "K").result(),
B().result()
)
return if (results.all { it == "OK" }) "OK" else "fail"
}
}
@@ -0,0 +1,13 @@
// TARGET_BACKEND: JVM_IR
// IGNORE_BACKEND_FIR: JVM_IR
// WITH_RUNTIME
context(Collection<P>) class A<P> {
val result = if (!isEmpty()) "OK" else "fail"
}
fun box(): String {
with (listOf(1, 2, 3)) {
return A().result
}
}
@@ -0,0 +1,10 @@
// TARGET_BACKEND: JVM_IR
// IGNORE_BACKEND_FIR: JVM_IR
context(T) class B<T : CharSequence> {
val result = if (length == 2) "OK" else "fail"
}
fun box() = with("OK") {
B().result
}
@@ -0,0 +1,15 @@
// TARGET_BACKEND: JVM_IR
// IGNORE_BACKEND_FIR: JVM_IR
class A {
val ok = "OK"
}
context(A)
class B {
fun result() = ok
}
fun box() = with(A()) {
B().result()
}