Skip to content

Commit

Permalink
[FIR] Report about recursion in implicit types for receivers of invoke
Browse files Browse the repository at this point in the history
^KT-65576 Fixed
  • Loading branch information
demiurg906 authored and qodana-bot committed Feb 27, 2024
1 parent 234cc5b commit 6f6e37f
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,7 @@ import org.jetbrains.kotlin.fir.resolve.*
import org.jetbrains.kotlin.fir.resolve.calls.*
import org.jetbrains.kotlin.fir.resolve.diagnostics.ConePropertyAsOperator
import org.jetbrains.kotlin.fir.symbols.impl.*
import org.jetbrains.kotlin.fir.types.ConeClassLikeType
import org.jetbrains.kotlin.fir.types.coneTypeUnsafe
import org.jetbrains.kotlin.fir.types.isExtensionFunctionType
import org.jetbrains.kotlin.fir.types.typeApproximator
import org.jetbrains.kotlin.fir.types.*
import org.jetbrains.kotlin.resolve.calls.tasks.ExplicitReceiverKind
import org.jetbrains.kotlin.resolve.calls.tower.CandidateApplicability
import org.jetbrains.kotlin.types.AbstractTypeChecker
Expand Down Expand Up @@ -317,15 +314,22 @@ private fun BodyResolveComponents.createExplicitReceiverForInvokeByCallable(
): FirExpression {
return FirPropertyAccessExpressionBuilder().apply {
val fakeSource = info.fakeSourceForImplicitInvokeCallReceiver
val returnTypeRef = returnTypeCalculator.tryCalculateReturnType(symbol.fir)
calleeReference = when {
returnTypeRef is FirErrorTypeRef -> FirErrorReferenceWithCandidate(
fakeSource, symbol.callableId.callableName, candidate, returnTypeRef.diagnostic,
)

candidate.isSuccessful -> FirNamedReferenceWithCandidate(fakeSource, symbol.callableId.callableName, candidate)

else -> FirErrorReferenceWithCandidate(
fakeSource, symbol.callableId.callableName, candidate,
createConeDiagnosticForCandidateWithError(candidate.applicability, candidate),
)
}
dispatchReceiver = candidate.dispatchReceiverExpression()
coneTypeOrNull = returnTypeCalculator.tryCalculateReturnType(symbol.fir).type

coneTypeOrNull = returnTypeRef.type

if (!invokeBuiltinExtensionMode) {
extensionReceiver = extensionReceiverExpression
Expand Down
4 changes: 2 additions & 2 deletions compiler/testData/diagnostics/tests/delegation/kt44843.fir.kt
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
// WITH_STDLIB

// FILE: test.kt
val bar2 by <!NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER, NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER!>bar2<!><!NO_VALUE_FOR_PARAMETER!>()<!>
val bar2 by <!NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER, NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER, RECURSION_IN_IMPLICIT_TYPES!>bar2<!><!NO_VALUE_FOR_PARAMETER!>()<!>

// 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!>bar<!><!NO_VALUE_FOR_PARAMETER!>()<!>
val bar by <!NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER, NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER, RECURSION_IN_IMPLICIT_TYPES!>bar<!><!NO_VALUE_FOR_PARAMETER!>()<!>
}

// FILE: lt/neworld/compiler/bar/Bar.kt
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ fun poll11(flag: Boolean) {

fun poll12(flag: Boolean) {
val inv = if (flag) { ::<!UNRESOLVED_REFERENCE!>bar3<!> } else { ::<!UNRESOLVED_REFERENCE!>foo3<!> }
inv<!NO_VALUE_FOR_PARAMETER!>()<!>
<!CANNOT_INFER_PARAMETER_TYPE!>inv<!><!NO_VALUE_FOR_PARAMETER!>()<!>
}

fun poll13(flag: Boolean) {
Expand All @@ -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<!> }<!>
inv<!NO_VALUE_FOR_PARAMETER!>()<!>
<!CANNOT_INFER_PARAMETER_TYPE!>inv<!><!NO_VALUE_FOR_PARAMETER!>()<!>
}

fun poll15(flag: Boolean) {
val inv = if (flag) { ::<!UNRESOLVED_REFERENCE!>bar5<!> } else { ::<!UNRESOLVED_REFERENCE!>foo5<!> }
inv<!NO_VALUE_FOR_PARAMETER!>()<!>
<!CANNOT_INFER_PARAMETER_TYPE!>inv<!><!NO_VALUE_FOR_PARAMETER!>()<!>
}

fun poll16(flag: Boolean) {
Expand All @@ -65,7 +65,7 @@ fun poll17(flag: Boolean) {

fun poll2(flag: Boolean) {
val inv = when (flag) { true -> ::<!UNRESOLVED_REFERENCE!>bar<!> else -> ::<!UNRESOLVED_REFERENCE!>foo<!> }
inv<!NO_VALUE_FOR_PARAMETER!>()<!>
<!CANNOT_INFER_PARAMETER_TYPE!>inv<!><!NO_VALUE_FOR_PARAMETER!>()<!>
}

fun poll21(flag: Boolean) {
Expand All @@ -75,12 +75,12 @@ fun poll21(flag: Boolean) {

fun poll22(flag: Boolean) {
val inv = when (flag) { true -> ::<!UNRESOLVED_REFERENCE!>bar3<!> else -> ::<!UNRESOLVED_REFERENCE!>foo3<!> }
inv<!NO_VALUE_FOR_PARAMETER!>()<!>
<!CANNOT_INFER_PARAMETER_TYPE!>inv<!><!NO_VALUE_FOR_PARAMETER!>()<!>
}

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<!> }<!>
inv<!NO_VALUE_FOR_PARAMETER!>()<!>
<!CANNOT_INFER_PARAMETER_TYPE!>inv<!><!NO_VALUE_FOR_PARAMETER!>()<!>
}

fun poll24(flag: Boolean) {
Expand All @@ -100,7 +100,7 @@ fun poll26(flag: Boolean) {

fun poll3(flag: Boolean) {
val inv = when (flag) { true -> ::<!UNRESOLVED_REFERENCE!>bar<!> false -> ::<!UNRESOLVED_REFERENCE!>foo<!> }
inv<!NO_VALUE_FOR_PARAMETER!>()<!>
<!CANNOT_INFER_PARAMETER_TYPE!>inv<!><!NO_VALUE_FOR_PARAMETER!>()<!>
}

fun poll31(flag: Boolean) {
Expand All @@ -110,12 +110,12 @@ fun poll31(flag: Boolean) {

fun poll32(flag: Boolean) {
val inv = when (flag) { true -> ::<!UNRESOLVED_REFERENCE!>bar3<!> false -> ::<!UNRESOLVED_REFERENCE!>foo3<!> }
inv<!NO_VALUE_FOR_PARAMETER!>()<!>
<!CANNOT_INFER_PARAMETER_TYPE!>inv<!><!NO_VALUE_FOR_PARAMETER!>()<!>
}

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<!> }<!>
inv<!NO_VALUE_FOR_PARAMETER!>()<!>
<!CANNOT_INFER_PARAMETER_TYPE!>inv<!><!NO_VALUE_FOR_PARAMETER!>()<!>
}

fun poll34(flag: Boolean) {
Expand All @@ -135,7 +135,7 @@ fun poll36(flag: Boolean) {

fun poll4() {
val inv = try { ::<!UNRESOLVED_REFERENCE!>bar<!> } finally { ::<!UNRESOLVED_REFERENCE!>foo<!> }
inv<!NO_VALUE_FOR_PARAMETER!>()<!>
<!CANNOT_INFER_PARAMETER_TYPE!>inv<!><!NO_VALUE_FOR_PARAMETER!>()<!>
}

fun poll41() {
Expand All @@ -145,17 +145,17 @@ fun poll41() {

fun poll42() {
val inv = try { ::<!UNRESOLVED_REFERENCE!>bar3<!> } finally { ::<!UNRESOLVED_REFERENCE!>foo3<!> }
inv<!NO_VALUE_FOR_PARAMETER!>()<!>
<!CANNOT_INFER_PARAMETER_TYPE!>inv<!><!NO_VALUE_FOR_PARAMETER!>()<!>
}

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<!> }<!>
inv<!NO_VALUE_FOR_PARAMETER!>()<!>
<!CANNOT_INFER_PARAMETER_TYPE!>inv<!><!NO_VALUE_FOR_PARAMETER!>()<!>
}

fun poll44() {
val inv = try { ::<!UNRESOLVED_REFERENCE!>bar5<!> } finally { ::<!UNRESOLVED_REFERENCE!>foo5<!> }
inv<!NO_VALUE_FOR_PARAMETER!>()<!>
<!CANNOT_INFER_PARAMETER_TYPE!>inv<!><!NO_VALUE_FOR_PARAMETER!>()<!>
}

fun poll45() {
Expand All @@ -170,7 +170,7 @@ fun poll46() {

fun poll5() {
val inv = try { ::<!UNRESOLVED_REFERENCE!>bar<!> } catch (e: Exception) { ::<!UNRESOLVED_REFERENCE!>foo<!> } finally { ::<!UNRESOLVED_REFERENCE!>foo<!> }
inv<!NO_VALUE_FOR_PARAMETER!>()<!>
<!CANNOT_INFER_PARAMETER_TYPE!>inv<!><!NO_VALUE_FOR_PARAMETER!>()<!>
}

fun poll51() {
Expand All @@ -180,17 +180,17 @@ fun poll51() {

fun poll52() {
val inv = try { ::<!UNRESOLVED_REFERENCE!>bar3<!> } catch (e: Exception) { ::<!UNRESOLVED_REFERENCE!>foo3<!> } finally { ::<!UNRESOLVED_REFERENCE!>foo3<!> }
inv<!NO_VALUE_FOR_PARAMETER!>()<!>
<!CANNOT_INFER_PARAMETER_TYPE!>inv<!><!NO_VALUE_FOR_PARAMETER!>()<!>
}

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<!> }<!>
inv<!NO_VALUE_FOR_PARAMETER!>()<!>
<!CANNOT_INFER_PARAMETER_TYPE!>inv<!><!NO_VALUE_FOR_PARAMETER!>()<!>
}

fun poll54() {
val inv = try { ::<!UNRESOLVED_REFERENCE!>bar5<!> } catch (e: Exception) { ::<!UNRESOLVED_REFERENCE!>foo5<!> } finally { ::<!UNRESOLVED_REFERENCE!>foo5<!> }
inv<!NO_VALUE_FOR_PARAMETER!>()<!>
<!CANNOT_INFER_PARAMETER_TYPE!>inv<!><!NO_VALUE_FOR_PARAMETER!>()<!>
}

fun poll55() {
Expand Down Expand Up @@ -240,7 +240,7 @@ fun poll66() {

fun poll7() {
val inv = ::<!UNRESOLVED_REFERENCE!>bar<!><!NOT_NULL_ASSERTION_ON_CALLABLE_REFERENCE!>!!<!>
inv<!NO_VALUE_FOR_PARAMETER!>()<!>
<!CANNOT_INFER_PARAMETER_TYPE!>inv<!><!NO_VALUE_FOR_PARAMETER!>()<!>
}

fun poll71() {
Expand All @@ -250,7 +250,7 @@ fun poll71() {

fun poll72() {
val inv = ::<!UNRESOLVED_REFERENCE!>bar3<!><!NOT_NULL_ASSERTION_ON_CALLABLE_REFERENCE!>!!<!>
inv<!NO_VALUE_FOR_PARAMETER!>()<!>
<!CANNOT_INFER_PARAMETER_TYPE!>inv<!><!NO_VALUE_FOR_PARAMETER!>()<!>
}

fun poll73() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ fun foo(): Int = 0
object Implicit {
operator fun Any.invoke(): String = "Fail"

val foo = foo()
val foo = <!RECURSION_IN_IMPLICIT_TYPES!>foo<!>()
}

object Explicit {
Expand All @@ -27,7 +27,7 @@ object ImplicitIndirect {

val foo get() = bar()
val bar get() = baz()
val baz get() = foo()
val baz get() = <!RECURSION_IN_IMPLICIT_TYPES!>foo<!>()
}

fun takeInt(x: Int) {}
Expand Down

0 comments on commit 6f6e37f

Please sign in to comment.