From ee143e937008c0f9d89c483439afaac04047d418 Mon Sep 17 00:00:00 2001 From: "Anastasia.Nekrasova" Date: Wed, 24 Jan 2024 21:54:33 +0200 Subject: [PATCH] [K2]: compiler crash on unresolved delegated extention receiver A report of UNRESOLVED_REFERENCE should not be made for elements like FirImplicitThisReference that don't have a source, as they are implicit. #KT-65044 Fixed --- ...icCompilerTestFirTestdataTestGenerated.java | 6 ++++++ ...nosticCompilerFirTestDataTestGenerated.java | 6 ++++++ .../testData/resolve/KT-65044.fir.txt | 5 +++++ .../testData/resolve/KT-65044.kt | 1 + .../FirLightTreeDiagnosticsTestGenerated.java | 6 ++++++ .../runners/FirPsiDiagnosticTestGenerated.java | 6 ++++++ .../coneDiagnosticToFirDiagnostic.kt | 18 +++++++++++++----- 7 files changed, 43 insertions(+), 5 deletions(-) create mode 100644 compiler/fir/analysis-tests/testData/resolve/KT-65044.fir.txt create mode 100644 compiler/fir/analysis-tests/testData/resolve/KT-65044.kt diff --git a/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/DiagnosticCompilerTestFirTestdataTestGenerated.java b/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/DiagnosticCompilerTestFirTestdataTestGenerated.java index 1bbcfd0be91..4cc07ca7d54 100644 --- a/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/DiagnosticCompilerTestFirTestdataTestGenerated.java +++ b/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/DiagnosticCompilerTestFirTestdataTestGenerated.java @@ -404,6 +404,12 @@ public class DiagnosticCompilerTestFirTestdataTestGenerated extends AbstractDiag runTest("compiler/fir/analysis-tests/testData/resolve/javaStaticScopeInheritance.kt"); } + @Test + @TestMetadata("KT-65044.kt") + public void testKT_65044() throws Exception { + runTest("compiler/fir/analysis-tests/testData/resolve/KT-65044.kt"); + } + @Test @TestMetadata("kt41984.kt") public void testKt41984() throws Exception { diff --git a/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/LLFirPreresolvedReversedDiagnosticCompilerFirTestDataTestGenerated.java b/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/LLFirPreresolvedReversedDiagnosticCompilerFirTestDataTestGenerated.java index 5880cc27a73..f10825d19b3 100644 --- a/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/LLFirPreresolvedReversedDiagnosticCompilerFirTestDataTestGenerated.java +++ b/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/LLFirPreresolvedReversedDiagnosticCompilerFirTestDataTestGenerated.java @@ -404,6 +404,12 @@ public class LLFirPreresolvedReversedDiagnosticCompilerFirTestDataTestGenerated runTest("compiler/fir/analysis-tests/testData/resolve/javaStaticScopeInheritance.kt"); } + @Test + @TestMetadata("KT-65044.kt") + public void testKT_65044() throws Exception { + runTest("compiler/fir/analysis-tests/testData/resolve/KT-65044.kt"); + } + @Test @TestMetadata("kt41984.kt") public void testKt41984() throws Exception { diff --git a/compiler/fir/analysis-tests/testData/resolve/KT-65044.fir.txt b/compiler/fir/analysis-tests/testData/resolve/KT-65044.fir.txt new file mode 100644 index 00000000000..d741940546c --- /dev/null +++ b/compiler/fir/analysis-tests/testData/resolve/KT-65044.fir.txt @@ -0,0 +1,5 @@ +FILE: KT-65044.kt + public final val .b: by #.#() + public get(): { + ^ D|/b|.#(this@R|/b|, ::R|/b|) + } diff --git a/compiler/fir/analysis-tests/testData/resolve/KT-65044.kt b/compiler/fir/analysis-tests/testData/resolve/KT-65044.kt new file mode 100644 index 00000000000..9668aa07e25 --- /dev/null +++ b/compiler/fir/analysis-tests/testData/resolve/KT-65044.kt @@ -0,0 +1 @@ +val A.b: A? by A.test() diff --git a/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirLightTreeDiagnosticsTestGenerated.java b/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirLightTreeDiagnosticsTestGenerated.java index f6b87e11fc0..daae5c39ab4 100644 --- a/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirLightTreeDiagnosticsTestGenerated.java +++ b/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirLightTreeDiagnosticsTestGenerated.java @@ -404,6 +404,12 @@ public class FirLightTreeDiagnosticsTestGenerated extends AbstractFirLightTreeDi runTest("compiler/fir/analysis-tests/testData/resolve/javaStaticScopeInheritance.kt"); } + @Test + @TestMetadata("KT-65044.kt") + public void testKT_65044() throws Exception { + runTest("compiler/fir/analysis-tests/testData/resolve/KT-65044.kt"); + } + @Test @TestMetadata("kt41984.kt") public void testKt41984() throws Exception { diff --git a/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirPsiDiagnosticTestGenerated.java b/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirPsiDiagnosticTestGenerated.java index 6bd0a51d173..582a8d8815d 100644 --- a/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirPsiDiagnosticTestGenerated.java +++ b/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirPsiDiagnosticTestGenerated.java @@ -404,6 +404,12 @@ public class FirPsiDiagnosticTestGenerated extends AbstractFirPsiDiagnosticTest runTest("compiler/fir/analysis-tests/testData/resolve/javaStaticScopeInheritance.kt"); } + @Test + @TestMetadata("KT-65044.kt") + public void testKT_65044() throws Exception { + runTest("compiler/fir/analysis-tests/testData/resolve/KT-65044.kt"); + } + @Test @TestMetadata("kt41984.kt") public void testKt41984() throws Exception { diff --git a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/diagnostics/coneDiagnosticToFirDiagnostic.kt b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/diagnostics/coneDiagnosticToFirDiagnostic.kt index b80e1fc4022..e53da2d9414 100644 --- a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/diagnostics/coneDiagnosticToFirDiagnostic.kt +++ b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/diagnostics/coneDiagnosticToFirDiagnostic.kt @@ -59,15 +59,23 @@ private fun ConeDiagnostic.toKtDiagnostic( is ConeUnresolvedSymbolError -> FirErrors.UNRESOLVED_REFERENCE.createOn(source, this.classId.asString(), null) is ConeUnresolvedNameError -> FirErrors.UNRESOLVED_REFERENCE.createOn(source, name.asString(), operatorToken) is ConeUnresolvedTypeQualifierError -> { - if (source?.kind == KtRealSourceElementKind) { + when { + // There could be an implicit reference here, such as FirImplicitThisReference, + // or other implicit elements without a source. + // In that case, it's not necessary to report UNRESOLVED_REFERENCE because they are implicit. + source == null -> null + // this.qualifiers will contain all resolved qualifiers from the left up to (including) the first unresolved qualifier. // We want to report UNRESOLVED_REFERENCE exactly on the first unresolved qualifier with its name as argument. // Examples: Unresolved, Unresolved.Foo, // Resolved.Unresolved, Resolved.Unresolved.Foo - val lastQualifier = this.qualifiers.last() - FirErrors.UNRESOLVED_REFERENCE.createOn(lastQualifier.source, lastQualifier.name.asString(), null) - } else { - FirErrors.UNRESOLVED_REFERENCE.createOn(source, this.qualifier, null) + source.kind == KtRealSourceElementKind -> { + val lastQualifier = this.qualifiers.last() + FirErrors.UNRESOLVED_REFERENCE.createOn(lastQualifier.source, lastQualifier.name.asString(), null) + } + else -> { + FirErrors.UNRESOLVED_REFERENCE.createOn(source, this.qualifier, null) + } } } is ConeFunctionCallExpectedError -> FirErrors.FUNCTION_CALL_EXPECTED.createOn(source, this.name.asString(), this.hasValueParameters)