Files
kotlin-fork/compiler/testData/diagnostics/tests/operatorsOverloading/implicitInvokeOnPropertyInItsInitializer.fir.kt
T
Ilya Chernikov fecc5ba501 K2: do not try to resolve invoke on error receiver
If a potential receiver is resolved to an error type, we consider
any other type as a subtype of it and therefore may select
any candidate that we happen to find in a scope.
In particular, in the case of scripts, or code with a context receiver,
the receiver candidate resolved to a cycle was accepted as a receiver
to an invoke on a random class from stdlib.
The fix skips adding invoke resolve task in this case, allowing
the tower to find the correct candidate in another scope.

#KT-64241 fixed
#KT-65576 fixed
2024-03-19 15:38:35 +00:00

43 lines
1002 B
Kotlin
Vendored

// ISSUE: KT-65576
fun foo(): Int = 0
object Implicit {
operator fun Any.invoke(): String = "Fail"
val foo = foo()
}
object Explicit {
operator fun Any.invoke(): String = "Fail"
val foo: String = foo()
}
class Inv<T>(val value: T)
object ImplicitWrapped {
operator fun Inv<*>.invoke(): Inv<String> = Inv("Fail")
val foo = Inv(<!TYPECHECKER_HAS_RUN_INTO_RECURSIVE_PROBLEM!>foo<!>)()
}
object ImplicitIndirect {
operator fun Any.invoke(): String = "Fail"
val foo get() = bar()
val bar get() = baz()
val baz get() = foo()
}
fun takeInt(x: Int) {}
fun test() {
takeInt(Implicit.foo)
takeInt(<!ARGUMENT_TYPE_MISMATCH!>Explicit.foo<!>) // should be an error
takeInt(<!ARGUMENT_TYPE_MISMATCH!>ImplicitWrapped.foo<!>) // should be an error
takeInt(<!ARGUMENT_TYPE_MISMATCH!>ImplicitIndirect.foo<!>) // should be an error
takeInt(<!ARGUMENT_TYPE_MISMATCH!>ImplicitIndirect.bar<!>) // should be an error
takeInt(ImplicitIndirect.baz)
}