K2: Fix current behavior for KT-37375 and KT-58943

This commit is contained in:
Denis.Zharkov
2023-05-26 17:38:14 +02:00
committed by Space Team
parent f37dc27974
commit acb1859154
11 changed files with 184 additions and 0 deletions
@@ -0,0 +1,17 @@
// ISSUE: KT-37375
val foo: Any = Any()
fun bar() {
operator fun Any.invoke(): String = ""
fun baz() {
operator fun Any.invoke(): Int = 1
fun barbaz() {
takeInt(<!OVERLOAD_RESOLUTION_AMBIGUITY!>foo<!>())
}
}
}
fun takeInt(x: Int) {}
@@ -0,0 +1,17 @@
// ISSUE: KT-37375
val foo: Any = Any()
fun bar() {
operator fun Any.invoke(): String = ""
fun baz() {
operator fun Any.invoke(): Int = 1
fun barbaz() {
takeInt(foo())
}
}
}
fun takeInt(x: Int) {}
@@ -0,0 +1,14 @@
// ISSUE: KT-37375
fun takeDouble(x: Double) {}
val bar: Int = 1
operator fun Double.invoke(): Double = 1.0 // (1)
fun test_1() {
val bar: Double = 2.0
operator fun Int.invoke(): Int = 1 // (2)
val res = bar() // should resolve to (1)
takeDouble(<!ARGUMENT_TYPE_MISMATCH!>res<!>) // should be OK
}
@@ -0,0 +1,14 @@
// ISSUE: KT-37375
fun takeDouble(x: Double) {}
val bar: Int = 1
operator fun Double.invoke(): Double = 1.0 // (1)
fun test_1() {
val bar: Double = 2.0
operator fun Int.invoke(): Int = 1 // (2)
val res = bar() // should resolve to (1)
takeDouble(res) // should be OK
}
@@ -0,0 +1,16 @@
// ISSUE: KT-58943
class A {
fun bar() {
val foo: String.() -> Int = { 1 } // (1)
fun String.foo(): String = "" // (2)
with("2") {
// In K1, foo variable + invokeExtension on implicit receiver is more prioritized than `foo() + implicit receiver`
// So, for now, we're going to preserve that behavior in K2
// For design, see KT-59528
takeInt(<!ARGUMENT_TYPE_MISMATCH!>foo()<!>)
}
}
}
fun takeInt(x: Int) {}
@@ -0,0 +1,16 @@
// ISSUE: KT-58943
class A {
fun bar() {
val foo: String.() -> Int = { 1 } // (1)
fun String.foo(): String = "" // (2)
with("2") {
// In K1, foo variable + invokeExtension on implicit receiver is more prioritized than `foo() + implicit receiver`
// So, for now, we're going to preserve that behavior in K2
// For design, see KT-59528
takeInt(foo())
}
}
}
fun takeInt(x: Int) {}