KT-51247 Fix resolution of functional types with context receivers

This commit is contained in:
Pavel Mikhailovskii
2022-12-09 15:29:39 +00:00
committed by Space Team
parent a4bde57d44
commit 08767d572b
7 changed files with 71 additions and 23 deletions
@@ -0,0 +1,55 @@
//!LANGUAGE: +ContextReceivers
//TARGET_BACKEND: JVM_IR
interface Context
interface Receiver
interface Param
fun foo(context: Context, receiver: Receiver, p: Param) {}
context(Context)
fun bar(receiver: Receiver, p: Param) {}
context(Context)
fun Receiver.baz(p: Param) {}
fun box(): String {
var a: context(Context, Receiver, Param) () -> Unit // 3, 0, 0
a = ::foo
a = ::bar
a = Receiver::baz
var b: context(Context, Receiver) Param.() -> Unit // 2, 1, 0
b = ::foo
b = ::bar
b = Receiver::baz
var c: context(Context, Receiver) (Param) -> Unit // 2, 0, 1
c = ::foo
c = ::bar
c = Receiver::baz
var d: context(Context) Receiver.(Param) -> Unit // 1, 1, 1. This is the same as in KEEP.
d = ::foo
d = ::bar
d = Receiver::baz
var e: context(Context) (Receiver, Param) -> Unit // 1, 0, 2
e = ::foo
e = ::bar
e = Receiver::baz
var f: Context.(Receiver, Param) -> Unit // 0, 1, 2
f = ::foo
f = ::bar
f = Receiver::baz
var g: (Context, Receiver, Param) -> Unit // 0, 0, 3
g = ::foo
g = ::bar
g = Receiver::baz
return "OK"
}
@@ -1,21 +0,0 @@
// !LANGUAGE: +ContextReceivers
// !DIAGNOSTICS: -ASSIGNED_BUT_NEVER_ACCESSED_VARIABLE
class Context
class Receiver
class Param
fun foo(context: Context, receiver: Receiver, p: Param) {}
context(Context)
fun bar(receiver: Receiver, p: Param) {}
context(Context)
fun Receiver.baz(p: Param) {}
fun main() {
var g: context(Context) Receiver.(Param) -> Unit
g = ::foo // OK
g = ::<!UNRESOLVED_REFERENCE!>bar<!> // OK
g = Receiver::<!UNRESOLVED_REFERENCE!>baz<!> // OK
}
@@ -1,3 +1,4 @@
// FIR_IDENTICAL
// !LANGUAGE: +ContextReceivers
// !DIAGNOSTICS: -ASSIGNED_BUT_NEVER_ACCESSED_VARIABLE