From e989e6d3970ba741e6aba8737dd77290e42cc7a5 Mon Sep 17 00:00:00 2001 From: Dmitriy Novozhilov Date: Wed, 6 Mar 2024 11:18:59 +0200 Subject: [PATCH] [FIR] Don't compute getter return type if synthetic property is inapplicable Return type computation of getter for synthetic property, which is incompatible anyway (e.g. because there is no java in the hierarchy) may cause excess dependency between return types of declarations, which may lead to recursive problems in resolution ^KT-66313 Fixed --- .../kotlin/fir/resolve/calls/Synthetics.kt | 8 ++++---- .../resolve/complexOrderAndImplicitTypes.fir.kt | 15 --------------- .../tests/resolve/complexOrderAndImplicitTypes.kt | 1 + 3 files changed, 5 insertions(+), 19 deletions(-) delete mode 100644 compiler/testData/diagnostics/tests/resolve/complexOrderAndImplicitTypes.fir.kt diff --git a/compiler/fir/providers/src/org/jetbrains/kotlin/fir/resolve/calls/Synthetics.kt b/compiler/fir/providers/src/org/jetbrains/kotlin/fir/resolve/calls/Synthetics.kt index 28aae1566fe..c00722cb68a 100644 --- a/compiler/fir/providers/src/org/jetbrains/kotlin/fir/resolve/calls/Synthetics.kt +++ b/compiler/fir/providers/src/org/jetbrains/kotlin/fir/resolve/calls/Synthetics.kt @@ -115,6 +115,10 @@ class FirSyntheticPropertiesScope private constructor( if (getter.valueParameters.isNotEmpty()) return if (getter.isStatic) return + // Should have Java among overridden _and_ don't have isHiddenEverywhereBesideSuperCalls among them + val (getterCompatibility, deprecatedOverrideOfHidden) = getterSymbol.computeGetterCompatibility() + if (getterCompatibility == Incompatible) return + var getterReturnType = (getter.returnTypeRef as? FirResolvedTypeRef)?.type if (getterReturnType == null && needCheckForSetter) { // During implicit body resolve phase, we can encounter a reference to a not yet resolved Kotlin class that inherits a @@ -126,10 +130,6 @@ class FirSyntheticPropertiesScope private constructor( // And it doesn't make sense to make a synthetic property for `void` typed getters if (getterReturnType?.isUnit == true && CompilerConeAttributes.EnhancedNullability !in getterReturnType.attributes) return - // Should have Java among overridden _and_ don't have isHiddenEverywhereBesideSuperCalls among them - val (getterCompatibility, deprecatedOverrideOfHidden) = getterSymbol.computeGetterCompatibility() - if (getterCompatibility == Incompatible) return - var matchingSetter: FirSimpleFunction? = null if (needCheckForSetter && getterReturnType != null) { val setterName = syntheticNamesProvider.setterNameByGetterName(getterName) diff --git a/compiler/testData/diagnostics/tests/resolve/complexOrderAndImplicitTypes.fir.kt b/compiler/testData/diagnostics/tests/resolve/complexOrderAndImplicitTypes.fir.kt deleted file mode 100644 index 8fd5b72431d..00000000000 --- a/compiler/testData/diagnostics/tests/resolve/complexOrderAndImplicitTypes.fir.kt +++ /dev/null @@ -1,15 +0,0 @@ -// ISSUE: KT-66313 - -val foo: String get() = "" - -class Test1 { - private val otherFoo = foo - - fun getFoo() = otherFoo -} - -class Test2 { - fun getFoo() = otherFoo - - private val otherFoo = foo -} diff --git a/compiler/testData/diagnostics/tests/resolve/complexOrderAndImplicitTypes.kt b/compiler/testData/diagnostics/tests/resolve/complexOrderAndImplicitTypes.kt index 80b5a1a3924..c185acb9736 100644 --- a/compiler/testData/diagnostics/tests/resolve/complexOrderAndImplicitTypes.kt +++ b/compiler/testData/diagnostics/tests/resolve/complexOrderAndImplicitTypes.kt @@ -1,3 +1,4 @@ +// FIR_IDENTICAL // ISSUE: KT-66313 val foo: String get() = ""