[FIR] Resolve property return type before resolving its annotations

This fixes TYPECHECKER_HAS_RUN_INTO_RECURSIVE_PROBLEM in a declaration
like `@Ann(myConst) const val myConst = ""`.

#KT-58080 Fixed
This commit is contained in:
Kirill Rakhman
2023-05-05 17:11:57 +02:00
committed by Space Team
parent 1c7ffb3276
commit 7f9118d0f2
7 changed files with 46 additions and 13 deletions
@@ -24902,6 +24902,12 @@ public class DiagnosticCompilerTestFE10TestdataTestGenerated extends AbstractDia
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/diagnostics/tests/properties"), Pattern.compile("^(.+)\\.kt$"), Pattern.compile("^(.+)\\.(reversed|fir|ll)\\.kts?$"), true, "multiplatform");
}
@Test
@TestMetadata("constAnnotationCycle.kt")
public void testConstAnnotationCycle() throws Exception {
runTest("compiler/testData/diagnostics/tests/properties/constAnnotationCycle.kt");
}
@Test
@TestMetadata("extensionPropertyMustHaveAccessorsOrBeAbstract.kt")
public void testExtensionPropertyMustHaveAccessorsOrBeAbstract() throws Exception {
@@ -24902,6 +24902,12 @@ public class LLFirPreresolvedReversedDiagnosticCompilerFE10TestDataTestGenerated
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/diagnostics/tests/properties"), Pattern.compile("^(.+)\\.kt$"), Pattern.compile("^(.+)\\.(reversed|fir|ll)\\.kts?$"), true, "multiplatform");
}
@Test
@TestMetadata("constAnnotationCycle.kt")
public void testConstAnnotationCycle() throws Exception {
runTest("compiler/testData/diagnostics/tests/properties/constAnnotationCycle.kt");
}
@Test
@TestMetadata("extensionPropertyMustHaveAccessorsOrBeAbstract.kt")
public void testExtensionPropertyMustHaveAccessorsOrBeAbstract() throws Exception {
@@ -24902,6 +24902,12 @@ public class FirLightTreeOldFrontendDiagnosticsTestGenerated extends AbstractFir
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/diagnostics/tests/properties"), Pattern.compile("^(.+)\\.kt$"), Pattern.compile("^(.+)\\.(reversed|fir|ll)\\.kts?$"), true, "multiplatform");
}
@Test
@TestMetadata("constAnnotationCycle.kt")
public void testConstAnnotationCycle() throws Exception {
runTest("compiler/testData/diagnostics/tests/properties/constAnnotationCycle.kt");
}
@Test
@TestMetadata("extensionPropertyMustHaveAccessorsOrBeAbstract.kt")
public void testExtensionPropertyMustHaveAccessorsOrBeAbstract() throws Exception {
@@ -24908,6 +24908,12 @@ public class FirPsiOldFrontendDiagnosticsTestGenerated extends AbstractFirPsiDia
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/diagnostics/tests/properties"), Pattern.compile("^(.*)\\.kts?$"), Pattern.compile("^(.+)\\.(reversed|fir|ll)\\.kts?$"), true, "multiplatform");
}
@Test
@TestMetadata("constAnnotationCycle.kt")
public void testConstAnnotationCycle() throws Exception {
runTest("compiler/testData/diagnostics/tests/properties/constAnnotationCycle.kt");
}
@Test
@TestMetadata("extensionPropertyMustHaveAccessorsOrBeAbstract.kt")
public void testExtensionPropertyMustHaveAccessorsOrBeAbstract() throws Exception {
@@ -145,12 +145,20 @@ open class FirDeclarationsResolveTransformer(
context.withProperty(property) {
context.forPropertyInitializer {
if (!initializerIsAlreadyResolved) {
property.transformChildrenWithoutComponents(returnTypeRefBeforeResolve)
property.replaceBodyResolveState(FirPropertyBodyResolveState.INITIALIZER_RESOLVED)
val resolutionMode = withExpectedType(returnTypeRefBeforeResolve)
property.transformReturnTypeRef(transformer, resolutionMode)
.transformInitializer(transformer, resolutionMode)
.transformTypeParameters(transformer, resolutionMode)
.replaceBodyResolveState(FirPropertyBodyResolveState.INITIALIZER_RESOLVED)
}
// Return type needs to be resolved before resolving annotations (transformOtherChildren) because of a possible cycle
// @Ann(myConst) const val myConst = ""
if (property.initializer != null) {
storeVariableReturnType(property)
}
if (!initializerIsAlreadyResolved) {
property.transformOtherChildren(transformer, data)
}
val canResolveBackingFieldEarly = property.hasExplicitBackingField || property.returnTypeRef is FirResolvedTypeRef
if (!initializerIsAlreadyResolved && canResolveBackingFieldEarly) {
property.transformBackingField(transformer, withExpectedType(property.returnTypeRef))
@@ -412,17 +420,6 @@ open class FirDeclarationsResolveTransformer(
return variable
}
/**
* This function is expected to transform everything but property accessors, backing field and delegate
*/
private fun FirProperty.transformChildrenWithoutComponents(returnTypeRef: FirTypeRef): FirProperty {
val data = withExpectedType(returnTypeRef)
return transformReturnTypeRef(transformer, data)
.transformInitializer(transformer, data)
.transformTypeParameters(transformer, data)
.transformOtherChildren(transformer, data)
}
private fun FirProperty.transformAccessors(mayResolveSetter: Boolean = true) {
var enhancedTypeRef = returnTypeRef
if (bodyResolveState < FirPropertyBodyResolveState.INITIALIZER_AND_GETTER_RESOLVED) {
@@ -0,0 +1,6 @@
// FIR_IDENTICAL
annotation class Anno(val value: String)
@Anno(constant)
const val constant = "OK"
@@ -25680,6 +25680,12 @@ public class DiagnosticTestGenerated extends AbstractDiagnosticTest {
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/diagnostics/tests/properties"), Pattern.compile("^(.*)\\.kts?$"), Pattern.compile("^(.+)\\.(reversed|fir|ll)\\.kts?$"), true);
}
@Test
@TestMetadata("constAnnotationCycle.kt")
public void testConstAnnotationCycle() throws Exception {
runTest("compiler/testData/diagnostics/tests/properties/constAnnotationCycle.kt");
}
@Test
@TestMetadata("extensionPropertyMustHaveAccessorsOrBeAbstract.kt")
public void testExtensionPropertyMustHaveAccessorsOrBeAbstract() throws Exception {