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
This commit is contained in:
committed by
Space Team
parent
d5ad41fa28
commit
fecc5ba501
+4
-4
@@ -5,7 +5,7 @@ fun foo(): Int = 0
|
||||
object Implicit {
|
||||
operator fun Any.invoke(): String = "Fail"
|
||||
|
||||
val foo = <!RECURSION_IN_IMPLICIT_TYPES!>foo<!>()
|
||||
val foo = foo()
|
||||
}
|
||||
|
||||
object Explicit {
|
||||
@@ -27,16 +27,16 @@ object ImplicitIndirect {
|
||||
|
||||
val foo get() = bar()
|
||||
val bar get() = baz()
|
||||
val baz get() = <!RECURSION_IN_IMPLICIT_TYPES!>foo<!>()
|
||||
val baz get() = foo()
|
||||
}
|
||||
|
||||
fun takeInt(x: Int) {}
|
||||
|
||||
fun test() {
|
||||
takeInt(<!ARGUMENT_TYPE_MISMATCH!>Implicit.foo<!>) // should be an error
|
||||
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(<!ARGUMENT_TYPE_MISMATCH!>ImplicitIndirect.baz<!>) // should be an error
|
||||
takeInt(ImplicitIndirect.baz)
|
||||
}
|
||||
|
||||
compiler/testData/diagnostics/tests/operatorsOverloading/implicitInvokeOnPropertyInItsInitializer.kt
Vendored
+2
-2
@@ -33,10 +33,10 @@ object ImplicitIndirect {
|
||||
fun takeInt(x: Int) {}
|
||||
|
||||
fun test() {
|
||||
takeInt(Implicit.foo) // should be an error
|
||||
takeInt(Implicit.foo)
|
||||
takeInt(<!TYPE_MISMATCH!>Explicit.foo<!>) // should be an error
|
||||
takeInt(ImplicitWrapped.<!DEBUG_INFO_ELEMENT_WITH_ERROR_TYPE!>foo<!>) // should be an error
|
||||
takeInt(<!TYPE_MISMATCH!>ImplicitIndirect.foo<!>) // should be an error
|
||||
takeInt(<!TYPE_MISMATCH!>ImplicitIndirect.bar<!>) // should be an error
|
||||
takeInt(ImplicitIndirect.baz) // should be an error
|
||||
takeInt(ImplicitIndirect.baz)
|
||||
}
|
||||
|
||||
-17
@@ -1,17 +0,0 @@
|
||||
// !LANGUAGE: +ContextReceivers
|
||||
// WITH_STDLIB
|
||||
|
||||
interface C
|
||||
|
||||
fun C.foo(body: () -> Unit) {}
|
||||
|
||||
context(C)
|
||||
class A {
|
||||
val foo = <!NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER, RECURSION_IN_IMPLICIT_TYPES!>foo<!> {}
|
||||
}
|
||||
|
||||
fun C.test() {
|
||||
object {
|
||||
val foo = foo {}
|
||||
}
|
||||
}
|
||||
+1
@@ -1,3 +1,4 @@
|
||||
// FIR_IDENTICAL
|
||||
// !LANGUAGE: +ContextReceivers
|
||||
// WITH_STDLIB
|
||||
|
||||
|
||||
Reference in New Issue
Block a user