K2: build SAM-based function type for a given captured type properly

Before this commit, we assumed (erroneously) that a captured type
cannot have an associated SAM-based function type.
In this commit we changed this assumption, replacing a captured type
with its lower type for this purpose

#KT-63379 Fixed
This commit is contained in:
Mikhail Glukhikh
2023-12-20 17:11:46 +01:00
committed by Space Team
parent 8588588760
commit a02cf76d6c
10 changed files with 68 additions and 19 deletions
@@ -1,17 +0,0 @@
// ISSUE: KT-63379
class TestDummyClass<T> {
fun testFun(t: T) {}
}
fun more(t: TestDummyClass<in CustomRunnable>) {
t.testFun <!ARGUMENT_TYPE_MISMATCH!>{ Unit }<!>
t.testFun(CustomRunnable { Unit })
t.testFun(object : CustomRunnable {
override fun run() {}
})
}
fun interface CustomRunnable {
fun run()
}
@@ -1,3 +1,4 @@
// FIR_IDENTICAL
// ISSUE: KT-63379
class TestDummyClass<T> {
@@ -0,0 +1,17 @@
// ISSUE: KT-63379 (modified example, see original in unitInContravariantPosition.kt)
class TestDummyClass<T> {
fun testFun(t: T) {}
}
fun more(t: TestDummyClass<out CustomRunnable>) {
t.testFun <!ARGUMENT_TYPE_MISMATCH!>{ Unit }<!>
t.testFun(<!ARGUMENT_TYPE_MISMATCH!>CustomRunnable { Unit }<!>)
t.testFun(<!ARGUMENT_TYPE_MISMATCH!>object : CustomRunnable<!> {
override fun run() {}
})
}
fun interface CustomRunnable {
fun run()
}
@@ -0,0 +1,17 @@
// ISSUE: KT-63379 (modified example, see original in unitInContravariantPosition.kt)
class TestDummyClass<T> {
fun testFun(t: T) {}
}
fun more(t: TestDummyClass<out CustomRunnable>) {
t.testFun <!TYPE_MISMATCH!>{ Unit }<!>
t.testFun(<!TYPE_MISMATCH!>CustomRunnable { Unit }<!>)
t.testFun(<!TYPE_MISMATCH!>object : CustomRunnable<!> {
override fun run() {}
})
}
fun interface CustomRunnable {
fun run()
}