diff --git a/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/DiagnosticCompilerTestFE10TestdataTestGenerated.java b/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/DiagnosticCompilerTestFE10TestdataTestGenerated.java index 0a137b41f1c..b033771c261 100644 --- a/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/DiagnosticCompilerTestFE10TestdataTestGenerated.java +++ b/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/DiagnosticCompilerTestFE10TestdataTestGenerated.java @@ -23974,6 +23974,12 @@ public class DiagnosticCompilerTestFE10TestdataTestGenerated extends AbstractDia runTest("compiler/testData/diagnostics/tests/overload/overloadsFromCurrentAndSuperClassWithReturnType.kt"); } + @Test + @TestMetadata("RedeclarationThroughDestructuring.kt") + public void testRedeclarationThroughDestructuring() throws Exception { + runTest("compiler/testData/diagnostics/tests/overload/RedeclarationThroughDestructuring.kt"); + } + @Test @TestMetadata("SyntheticAndNotSynthetic.kt") public void testSyntheticAndNotSynthetic() throws Exception { diff --git a/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/LLFirPreresolvedReversedDiagnosticCompilerFE10TestDataTestGenerated.java b/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/LLFirPreresolvedReversedDiagnosticCompilerFE10TestDataTestGenerated.java index 3d4529231df..a68525c70e8 100644 --- a/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/LLFirPreresolvedReversedDiagnosticCompilerFE10TestDataTestGenerated.java +++ b/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/LLFirPreresolvedReversedDiagnosticCompilerFE10TestDataTestGenerated.java @@ -23974,6 +23974,12 @@ public class LLFirPreresolvedReversedDiagnosticCompilerFE10TestDataTestGenerated runTest("compiler/testData/diagnostics/tests/overload/overloadsFromCurrentAndSuperClassWithReturnType.kt"); } + @Test + @TestMetadata("RedeclarationThroughDestructuring.kt") + public void testRedeclarationThroughDestructuring() throws Exception { + runTest("compiler/testData/diagnostics/tests/overload/RedeclarationThroughDestructuring.kt"); + } + @Test @TestMetadata("SyntheticAndNotSynthetic.kt") public void testSyntheticAndNotSynthetic() throws Exception { diff --git a/compiler/fir/analysis-tests/testData/resolve/scopes/publicJavaAndPrivateKotlinVar.overrides.txt b/compiler/fir/analysis-tests/testData/resolve/scopes/publicJavaAndPrivateKotlinVar.overrides.txt index f285a8ad35d..5efce24008f 100644 --- a/compiler/fir/analysis-tests/testData/resolve/scopes/publicJavaAndPrivateKotlinVar.overrides.txt +++ b/compiler/fir/analysis-tests/testData/resolve/scopes/publicJavaAndPrivateKotlinVar.overrides.txt @@ -4,7 +4,7 @@ C: [Source]: public open override fun setName(newName: R|kotlin/String|): R|kotlin/Any?| from Use site scope of /C [id: 0] [SubstitutionOverride(DeclarationSite)]: public abstract fun setName(newName: R|kotlin/String!|): R|kotlin/Any!| from Substitution scope for [Java enhancement scope for /B] for type C [id: 1] [Enhancement]: public abstract fun setName(newName: R|kotlin/String!|): R|ft| from Java enhancement scope for /B [id: 2] - [Source]: private final var name: R|kotlin/String| = R|/name| from Use site scope of /C [id: 0] + [Source]: private final var name: R|kotlin/String| from Use site scope of /C [id: 0] D: [Source]: public open override fun getName(): R|kotlin/String| from Java enhancement scope for /D [id: 0] @@ -12,6 +12,6 @@ D: [Source]: public open override fun setName(newName: R|kotlin/String|): R|kotlin/Any?| from Java enhancement scope for /D [id: 0] [SubstitutionOverride(DeclarationSite)]: public abstract fun setName(newName: R|kotlin/String!|): R|kotlin/Any!| from Substitution scope for [Java enhancement scope for /B] for type C [id: 1] [Enhancement]: public abstract fun setName(newName: R|kotlin/String!|): R|ft| from Java enhancement scope for /B [id: 2] - [Source]: private final var name: R|kotlin/String| = R|/name| from Java enhancement scope for /D [id: 0] - [Source]: private final var name: R|kotlin/String| = R|/name| from Use site scope of /C [id: 0] + [Source]: private final var name: R|kotlin/String| from Java enhancement scope for /D [id: 0] + [Source]: private final var name: R|kotlin/String| from Use site scope of /C [id: 0] diff --git a/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirLightTreeOldFrontendDiagnosticsTestGenerated.java b/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirLightTreeOldFrontendDiagnosticsTestGenerated.java index 215ac9b2d5a..63cb274391e 100644 --- a/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirLightTreeOldFrontendDiagnosticsTestGenerated.java +++ b/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirLightTreeOldFrontendDiagnosticsTestGenerated.java @@ -23974,6 +23974,12 @@ public class FirLightTreeOldFrontendDiagnosticsTestGenerated extends AbstractFir runTest("compiler/testData/diagnostics/tests/overload/overloadsFromCurrentAndSuperClassWithReturnType.kt"); } + @Test + @TestMetadata("RedeclarationThroughDestructuring.kt") + public void testRedeclarationThroughDestructuring() throws Exception { + runTest("compiler/testData/diagnostics/tests/overload/RedeclarationThroughDestructuring.kt"); + } + @Test @TestMetadata("SyntheticAndNotSynthetic.kt") public void testSyntheticAndNotSynthetic() throws Exception { diff --git a/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirPsiOldFrontendDiagnosticsTestGenerated.java b/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirPsiOldFrontendDiagnosticsTestGenerated.java index 9c53fa253be..d47b9cf04ff 100644 --- a/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirPsiOldFrontendDiagnosticsTestGenerated.java +++ b/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirPsiOldFrontendDiagnosticsTestGenerated.java @@ -23980,6 +23980,12 @@ public class FirPsiOldFrontendDiagnosticsTestGenerated extends AbstractFirPsiDia runTest("compiler/testData/diagnostics/tests/overload/overloadsFromCurrentAndSuperClassWithReturnType.kt"); } + @Test + @TestMetadata("RedeclarationThroughDestructuring.kt") + public void testRedeclarationThroughDestructuring() throws Exception { + runTest("compiler/testData/diagnostics/tests/overload/RedeclarationThroughDestructuring.kt"); + } + @Test @TestMetadata("SyntheticAndNotSynthetic.kt") public void testSyntheticAndNotSynthetic() throws Exception { diff --git a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/diagnostics/FirDiagnosticRenderers.kt b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/diagnostics/FirDiagnosticRenderers.kt index aaaa864da29..3895667a083 100644 --- a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/diagnostics/FirDiagnosticRenderers.kt +++ b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/diagnostics/FirDiagnosticRenderers.kt @@ -42,6 +42,7 @@ object FirDiagnosticRenderers { callArgumentsRenderer = FirCallNoArgumentsRenderer(), modifierRenderer = FirPartialModifierRenderer(), valueParameterRenderer = FirValueParameterRendererNoDefaultValue(), + declarationRenderer = FirDeclarationRenderer("local ") ).renderElementAsString(symbol.fir, trim = true) is FirTypeParameterSymbol -> symbol.name.asString() else -> "???" diff --git a/compiler/fir/tree/src/org/jetbrains/kotlin/fir/renderer/FirBodyRenderer.kt b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/renderer/FirBodyRenderer.kt index c89bb35c871..55fb011f0a2 100644 --- a/compiler/fir/tree/src/org/jetbrains/kotlin/fir/renderer/FirBodyRenderer.kt +++ b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/renderer/FirBodyRenderer.kt @@ -6,6 +6,7 @@ package org.jetbrains.kotlin.fir.renderer import org.jetbrains.kotlin.fir.declarations.FirFunction +import org.jetbrains.kotlin.fir.declarations.FirVariable import org.jetbrains.kotlin.fir.expressions.FirBlock import org.jetbrains.kotlin.fir.expressions.FirDelegatedConstructorCall import org.jetbrains.kotlin.fir.expressions.FirLazyBlock @@ -23,6 +24,17 @@ class FirBodyRenderer { renderBody(function.body) } + fun render(variable: FirVariable) { + variable.initializer?.let { + printer.print(" = ") + it.accept(visitor) + } + variable.delegate?.let { + printer.print("by ") + it.accept(visitor) + } + } + fun renderBody(block: FirBlock?, additionalStatements: List = emptyList()) { if (block == null) return when (block) { diff --git a/compiler/fir/tree/src/org/jetbrains/kotlin/fir/renderer/FirDeclarationRenderer.kt b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/renderer/FirDeclarationRenderer.kt index 8e8016c01cf..dc43d2c8740 100644 --- a/compiler/fir/tree/src/org/jetbrains/kotlin/fir/renderer/FirDeclarationRenderer.kt +++ b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/renderer/FirDeclarationRenderer.kt @@ -10,7 +10,9 @@ import org.jetbrains.kotlin.fir.declarations.impl.FirErrorConstructor import org.jetbrains.kotlin.fir.isCatchParameter import org.jetbrains.kotlin.util.capitalizeDecapitalize.toLowerCaseAsciiOnly -open class FirDeclarationRenderer { +open class FirDeclarationRenderer( + private val localVariablePrefix: String = "l", +) { internal lateinit var components: FirRendererComponents protected val printer get() = components.printer @@ -40,7 +42,7 @@ open class FirDeclarationRenderer { if (declaration.isCatchParameter == true) { "" } else { - val prefix = if (declaration.isLocal) "l" else "" + val prefix = if (declaration.isLocal) localVariablePrefix else "" prefix + if (declaration.isVal) "val" else "var" } } @@ -61,4 +63,4 @@ open class FirDeclarationRenderer { protected open fun FirDeclaration.renderDeclarationAttributes() { } -} \ No newline at end of file +} diff --git a/compiler/fir/tree/src/org/jetbrains/kotlin/fir/renderer/FirRenderer.kt b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/renderer/FirRenderer.kt index 1dd461e9608..ad988bdb326 100644 --- a/compiler/fir/tree/src/org/jetbrains/kotlin/fir/renderer/FirRenderer.kt +++ b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/renderer/FirRenderer.kt @@ -305,14 +305,7 @@ class FirRenderer( override fun visitVariable(variable: FirVariable) { visitCallableDeclaration(variable) - variable.initializer?.let { - print(" = ") - it.accept(this) - } - variable.delegate?.let { - print("by ") - it.accept(this) - } + bodyRenderer?.render(variable) } override fun visitField(field: FirField) { diff --git a/compiler/testData/diagnostics/tests/imports/EnumEntryVsStaticAmbiguity.fir.diag.txt b/compiler/testData/diagnostics/tests/imports/EnumEntryVsStaticAmbiguity.fir.diag.txt index 2e429e36938..4c7707671f7 100644 --- a/compiler/testData/diagnostics/tests/imports/EnumEntryVsStaticAmbiguity.fir.diag.txt +++ b/compiler/testData/diagnostics/tests/imports/EnumEntryVsStaticAmbiguity.fir.diag.txt @@ -1 +1 @@ -/test.kt:(154,158): error: Overload resolution ambiguity between candidates: [static field SOME: String = String(Some), static enum entry SOME: SomeEnum] +/test.kt:(154,158): error: Overload resolution ambiguity between candidates: [static field SOME: String, static enum entry SOME: SomeEnum] diff --git a/compiler/testData/diagnostics/tests/imports/EnumEntryVsStaticAmbiguity3.fir.diag.txt b/compiler/testData/diagnostics/tests/imports/EnumEntryVsStaticAmbiguity3.fir.diag.txt index 807716796a8..eaf3c3708a1 100644 --- a/compiler/testData/diagnostics/tests/imports/EnumEntryVsStaticAmbiguity3.fir.diag.txt +++ b/compiler/testData/diagnostics/tests/imports/EnumEntryVsStaticAmbiguity3.fir.diag.txt @@ -1 +1 @@ -/test.kt:(160,164): error: Overload resolution ambiguity between candidates: [static field SOME: String = String(Some), static enum entry SOME: SomeEnum] +/test.kt:(160,164): error: Overload resolution ambiguity between candidates: [static field SOME: String, static enum entry SOME: SomeEnum] diff --git a/compiler/testData/diagnostics/tests/overload/RedeclarationThroughDestructuring.diag.txt b/compiler/testData/diagnostics/tests/overload/RedeclarationThroughDestructuring.diag.txt new file mode 100644 index 00000000000..65662e75a16 --- /dev/null +++ b/compiler/testData/diagnostics/tests/overload/RedeclarationThroughDestructuring.diag.txt @@ -0,0 +1,6 @@ +/RedeclarationThroughDestructuring.kt:5:14: error: conflicting declarations: val b: String, val b: Int + val (b, b) = e + ^ +/RedeclarationThroughDestructuring.kt:5:17: error: conflicting declarations: val b: String, val b: Int + val (b, b) = e + ^ diff --git a/compiler/testData/diagnostics/tests/overload/RedeclarationThroughDestructuring.fir.diag.txt b/compiler/testData/diagnostics/tests/overload/RedeclarationThroughDestructuring.fir.diag.txt new file mode 100644 index 00000000000..ed23de45813 --- /dev/null +++ b/compiler/testData/diagnostics/tests/overload/RedeclarationThroughDestructuring.fir.diag.txt @@ -0,0 +1,3 @@ +/RedeclarationThroughDestructuring.fir.kt:(133,134): error: Conflicting declarations: [local val b: String, local val b: Int] + +/RedeclarationThroughDestructuring.fir.kt:(136,137): error: Conflicting declarations: [local val b: String, local val b: Int] diff --git a/compiler/testData/diagnostics/tests/overload/RedeclarationThroughDestructuring.fir.kt b/compiler/testData/diagnostics/tests/overload/RedeclarationThroughDestructuring.fir.kt new file mode 100644 index 00000000000..ae98db26820 --- /dev/null +++ b/compiler/testData/diagnostics/tests/overload/RedeclarationThroughDestructuring.fir.kt @@ -0,0 +1,8 @@ +// RENDER_DIAGNOSTICS_FULL_TEXT + +data class Example(val a: String, val b: Int) { + fun testRedeclaration(e: Example){ + val (b, b) = e + } + +} diff --git a/compiler/testData/diagnostics/tests/overload/RedeclarationThroughDestructuring.kt b/compiler/testData/diagnostics/tests/overload/RedeclarationThroughDestructuring.kt new file mode 100644 index 00000000000..18e5a17418e --- /dev/null +++ b/compiler/testData/diagnostics/tests/overload/RedeclarationThroughDestructuring.kt @@ -0,0 +1,8 @@ +// RENDER_DIAGNOSTICS_FULL_TEXT + +data class Example(val a: String, val b: Int) { + fun testRedeclaration(e: Example){ + val (b, b) = e + } + +} diff --git a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/DiagnosticTestGenerated.java b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/DiagnosticTestGenerated.java index 95328c51c86..37d843aa3c7 100644 --- a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/DiagnosticTestGenerated.java +++ b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/DiagnosticTestGenerated.java @@ -25006,6 +25006,12 @@ public class DiagnosticTestGenerated extends AbstractDiagnosticTest { runTest("compiler/testData/diagnostics/tests/overload/overloadsFromCurrentAndSuperClassWithReturnType.kt"); } + @Test + @TestMetadata("RedeclarationThroughDestructuring.kt") + public void testRedeclarationThroughDestructuring() throws Exception { + runTest("compiler/testData/diagnostics/tests/overload/RedeclarationThroughDestructuring.kt"); + } + @Test @TestMetadata("SyntheticAndNotSynthetic.kt") public void testSyntheticAndNotSynthetic() throws Exception {