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
+2
@@ -178,6 +178,8 @@ internal class FirInvokeResolveTowerExtension(
|
||||
invokeReceiverCandidate, info, invokeBuiltinExtensionMode, extensionReceiverExpression
|
||||
) ?: continue
|
||||
|
||||
if (invokeReceiverExpression.resolvedType is ConeErrorType) continue
|
||||
|
||||
val invokeFunctionInfo =
|
||||
info.copy(
|
||||
explicitReceiver = invokeReceiverExpression,
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
// WITH_STDLIB
|
||||
|
||||
// FILE: test.kt
|
||||
val bar2 by <!NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER, NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER, RECURSION_IN_IMPLICIT_TYPES!>bar2<!><!NO_VALUE_FOR_PARAMETER!>()<!>
|
||||
val bar2 by <!UNRESOLVED_REFERENCE!>bar2<!>()
|
||||
|
||||
// FILE: lt/neworld/compiler/Foo.kt
|
||||
package lt.neworld.compiler
|
||||
|
||||
class Foo {
|
||||
val bar by <!NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER, NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER, RECURSION_IN_IMPLICIT_TYPES!>bar<!><!NO_VALUE_FOR_PARAMETER!>()<!>
|
||||
val bar by <!UNRESOLVED_REFERENCE!>bar<!>()
|
||||
}
|
||||
|
||||
// FILE: lt/neworld/compiler/bar/Bar.kt
|
||||
|
||||
+19
-19
@@ -35,7 +35,7 @@ fun poll11(flag: Boolean) {
|
||||
|
||||
fun poll12(flag: Boolean) {
|
||||
val inv = if (flag) { ::<!UNRESOLVED_REFERENCE!>bar3<!> } else { ::<!UNRESOLVED_REFERENCE!>foo3<!> }
|
||||
<!CANNOT_INFER_PARAMETER_TYPE!>inv<!><!NO_VALUE_FOR_PARAMETER!>()<!>
|
||||
<!UNRESOLVED_REFERENCE!>inv<!>()
|
||||
}
|
||||
|
||||
fun poll13(flag: Boolean) {
|
||||
@@ -45,12 +45,12 @@ fun poll13(flag: Boolean) {
|
||||
|
||||
fun poll14(flag: Boolean) {
|
||||
val inv = <!NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER!>if (flag) { ::<!NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER!>bar4<!> } else { ::<!NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER!>foo4<!> }<!>
|
||||
<!CANNOT_INFER_PARAMETER_TYPE!>inv<!><!NO_VALUE_FOR_PARAMETER!>()<!>
|
||||
<!UNRESOLVED_REFERENCE!>inv<!>()
|
||||
}
|
||||
|
||||
fun poll15(flag: Boolean) {
|
||||
val inv = if (flag) { ::<!UNRESOLVED_REFERENCE!>bar5<!> } else { ::<!UNRESOLVED_REFERENCE!>foo5<!> }
|
||||
<!CANNOT_INFER_PARAMETER_TYPE!>inv<!><!NO_VALUE_FOR_PARAMETER!>()<!>
|
||||
<!UNRESOLVED_REFERENCE!>inv<!>()
|
||||
}
|
||||
|
||||
fun poll16(flag: Boolean) {
|
||||
@@ -65,7 +65,7 @@ fun poll17(flag: Boolean) {
|
||||
|
||||
fun poll2(flag: Boolean) {
|
||||
val inv = when (flag) { true -> ::<!UNRESOLVED_REFERENCE!>bar<!> else -> ::<!UNRESOLVED_REFERENCE!>foo<!> }
|
||||
<!CANNOT_INFER_PARAMETER_TYPE!>inv<!><!NO_VALUE_FOR_PARAMETER!>()<!>
|
||||
<!UNRESOLVED_REFERENCE!>inv<!>()
|
||||
}
|
||||
|
||||
fun poll21(flag: Boolean) {
|
||||
@@ -75,12 +75,12 @@ fun poll21(flag: Boolean) {
|
||||
|
||||
fun poll22(flag: Boolean) {
|
||||
val inv = when (flag) { true -> ::<!UNRESOLVED_REFERENCE!>bar3<!> else -> ::<!UNRESOLVED_REFERENCE!>foo3<!> }
|
||||
<!CANNOT_INFER_PARAMETER_TYPE!>inv<!><!NO_VALUE_FOR_PARAMETER!>()<!>
|
||||
<!UNRESOLVED_REFERENCE!>inv<!>()
|
||||
}
|
||||
|
||||
fun poll23(flag: Boolean) {
|
||||
val inv = <!NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER!>when (flag) { true -> ::<!NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER!>bar4<!> else -> ::<!NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER!>foo4<!> }<!>
|
||||
<!CANNOT_INFER_PARAMETER_TYPE!>inv<!><!NO_VALUE_FOR_PARAMETER!>()<!>
|
||||
<!UNRESOLVED_REFERENCE!>inv<!>()
|
||||
}
|
||||
|
||||
fun poll24(flag: Boolean) {
|
||||
@@ -100,7 +100,7 @@ fun poll26(flag: Boolean) {
|
||||
|
||||
fun poll3(flag: Boolean) {
|
||||
val inv = when (flag) { true -> ::<!UNRESOLVED_REFERENCE!>bar<!> false -> ::<!UNRESOLVED_REFERENCE!>foo<!> }
|
||||
<!CANNOT_INFER_PARAMETER_TYPE!>inv<!><!NO_VALUE_FOR_PARAMETER!>()<!>
|
||||
<!UNRESOLVED_REFERENCE!>inv<!>()
|
||||
}
|
||||
|
||||
fun poll31(flag: Boolean) {
|
||||
@@ -110,12 +110,12 @@ fun poll31(flag: Boolean) {
|
||||
|
||||
fun poll32(flag: Boolean) {
|
||||
val inv = when (flag) { true -> ::<!UNRESOLVED_REFERENCE!>bar3<!> false -> ::<!UNRESOLVED_REFERENCE!>foo3<!> }
|
||||
<!CANNOT_INFER_PARAMETER_TYPE!>inv<!><!NO_VALUE_FOR_PARAMETER!>()<!>
|
||||
<!UNRESOLVED_REFERENCE!>inv<!>()
|
||||
}
|
||||
|
||||
fun poll33(flag: Boolean) {
|
||||
val inv = <!NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER!>when (flag) { true -> ::<!NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER!>bar4<!> false -> ::<!NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER!>foo4<!> }<!>
|
||||
<!CANNOT_INFER_PARAMETER_TYPE!>inv<!><!NO_VALUE_FOR_PARAMETER!>()<!>
|
||||
<!UNRESOLVED_REFERENCE!>inv<!>()
|
||||
}
|
||||
|
||||
fun poll34(flag: Boolean) {
|
||||
@@ -135,7 +135,7 @@ fun poll36(flag: Boolean) {
|
||||
|
||||
fun poll4() {
|
||||
val inv = try { ::<!UNRESOLVED_REFERENCE!>bar<!> } finally { ::<!UNRESOLVED_REFERENCE!>foo<!> }
|
||||
<!CANNOT_INFER_PARAMETER_TYPE!>inv<!><!NO_VALUE_FOR_PARAMETER!>()<!>
|
||||
<!UNRESOLVED_REFERENCE!>inv<!>()
|
||||
}
|
||||
|
||||
fun poll41() {
|
||||
@@ -145,17 +145,17 @@ fun poll41() {
|
||||
|
||||
fun poll42() {
|
||||
val inv = try { ::<!UNRESOLVED_REFERENCE!>bar3<!> } finally { ::<!UNRESOLVED_REFERENCE!>foo3<!> }
|
||||
<!CANNOT_INFER_PARAMETER_TYPE!>inv<!><!NO_VALUE_FOR_PARAMETER!>()<!>
|
||||
<!UNRESOLVED_REFERENCE!>inv<!>()
|
||||
}
|
||||
|
||||
fun poll43() {
|
||||
val inv = <!NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER!>try { ::<!NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER!>bar4<!> } finally { ::<!NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER!>foo4<!> }<!>
|
||||
<!CANNOT_INFER_PARAMETER_TYPE!>inv<!><!NO_VALUE_FOR_PARAMETER!>()<!>
|
||||
<!UNRESOLVED_REFERENCE!>inv<!>()
|
||||
}
|
||||
|
||||
fun poll44() {
|
||||
val inv = try { ::<!UNRESOLVED_REFERENCE!>bar5<!> } finally { ::<!UNRESOLVED_REFERENCE!>foo5<!> }
|
||||
<!CANNOT_INFER_PARAMETER_TYPE!>inv<!><!NO_VALUE_FOR_PARAMETER!>()<!>
|
||||
<!UNRESOLVED_REFERENCE!>inv<!>()
|
||||
}
|
||||
|
||||
fun poll45() {
|
||||
@@ -170,7 +170,7 @@ fun poll46() {
|
||||
|
||||
fun poll5() {
|
||||
val inv = try { ::<!UNRESOLVED_REFERENCE!>bar<!> } catch (e: Exception) { ::<!UNRESOLVED_REFERENCE!>foo<!> } finally { ::<!UNRESOLVED_REFERENCE!>foo<!> }
|
||||
<!CANNOT_INFER_PARAMETER_TYPE!>inv<!><!NO_VALUE_FOR_PARAMETER!>()<!>
|
||||
<!UNRESOLVED_REFERENCE!>inv<!>()
|
||||
}
|
||||
|
||||
fun poll51() {
|
||||
@@ -180,17 +180,17 @@ fun poll51() {
|
||||
|
||||
fun poll52() {
|
||||
val inv = try { ::<!UNRESOLVED_REFERENCE!>bar3<!> } catch (e: Exception) { ::<!UNRESOLVED_REFERENCE!>foo3<!> } finally { ::<!UNRESOLVED_REFERENCE!>foo3<!> }
|
||||
<!CANNOT_INFER_PARAMETER_TYPE!>inv<!><!NO_VALUE_FOR_PARAMETER!>()<!>
|
||||
<!UNRESOLVED_REFERENCE!>inv<!>()
|
||||
}
|
||||
|
||||
fun poll53() {
|
||||
val inv = <!NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER!>try { ::<!NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER!>bar4<!> } catch (e: Exception) { ::<!NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER!>foo4<!> } finally { ::<!NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER!>foo4<!> }<!>
|
||||
<!CANNOT_INFER_PARAMETER_TYPE!>inv<!><!NO_VALUE_FOR_PARAMETER!>()<!>
|
||||
<!UNRESOLVED_REFERENCE!>inv<!>()
|
||||
}
|
||||
|
||||
fun poll54() {
|
||||
val inv = try { ::<!UNRESOLVED_REFERENCE!>bar5<!> } catch (e: Exception) { ::<!UNRESOLVED_REFERENCE!>foo5<!> } finally { ::<!UNRESOLVED_REFERENCE!>foo5<!> }
|
||||
<!CANNOT_INFER_PARAMETER_TYPE!>inv<!><!NO_VALUE_FOR_PARAMETER!>()<!>
|
||||
<!UNRESOLVED_REFERENCE!>inv<!>()
|
||||
}
|
||||
|
||||
fun poll55() {
|
||||
@@ -240,7 +240,7 @@ fun poll66() {
|
||||
|
||||
fun poll7() {
|
||||
val inv = ::<!UNRESOLVED_REFERENCE!>bar<!><!NOT_NULL_ASSERTION_ON_CALLABLE_REFERENCE!>!!<!>
|
||||
<!CANNOT_INFER_PARAMETER_TYPE!>inv<!><!NO_VALUE_FOR_PARAMETER!>()<!>
|
||||
<!UNRESOLVED_REFERENCE!>inv<!>()
|
||||
}
|
||||
|
||||
fun poll71() {
|
||||
@@ -250,7 +250,7 @@ fun poll71() {
|
||||
|
||||
fun poll72() {
|
||||
val inv = ::<!UNRESOLVED_REFERENCE!>bar3<!><!NOT_NULL_ASSERTION_ON_CALLABLE_REFERENCE!>!!<!>
|
||||
<!CANNOT_INFER_PARAMETER_TYPE!>inv<!><!NO_VALUE_FOR_PARAMETER!>()<!>
|
||||
<!UNRESOLVED_REFERENCE!>inv<!>()
|
||||
}
|
||||
|
||||
fun poll73() {
|
||||
|
||||
+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
|
||||
|
||||
|
||||
+1
-1
@@ -1,3 +1,3 @@
|
||||
// GRADLE_LIKE_SCRIPT
|
||||
|
||||
val projectApi = <!RECURSION_IN_IMPLICIT_TYPES!>projectApi<!> { <!UNRESOLVED_REFERENCE!>it<!> }
|
||||
val projectApi = projectApi { it }
|
||||
|
||||
Reference in New Issue
Block a user