From 6bed02fed3ec462ad9efd4bec7f3a5e35dc39036 Mon Sep 17 00:00:00 2001 From: Mikhail Glukhikh Date: Wed, 5 Jul 2023 11:51:44 +0200 Subject: [PATCH] K2: fix an exception during function resolve #KT-59649 Fixed --- .../DiagnosticCompilerTestFirTestdataTestGenerated.java | 6 ++++++ ...versedDiagnosticCompilerFirTestDataTestGenerated.java | 6 ++++++ .../kotlin/fir/LazyBodyIsNotTouchedTestGenerated.java | 5 +++++ .../testData/resolve/propertyGetterWithoutType.fir.txt | 9 +++++++++ .../testData/resolve/propertyGetterWithoutType.kt | 6 ++++++ .../runners/FirLightTreeDiagnosticsTestGenerated.java | 6 ++++++ .../test/runners/FirPsiDiagnosticTestGenerated.java | 6 ++++++ .../body/resolve/FirDeclarationsResolveTransformer.kt | 2 +- 8 files changed, 45 insertions(+), 1 deletion(-) create mode 100644 compiler/fir/analysis-tests/testData/resolve/propertyGetterWithoutType.fir.txt create mode 100644 compiler/fir/analysis-tests/testData/resolve/propertyGetterWithoutType.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 96a1fc0f35f..97b84f80305 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 @@ -530,6 +530,12 @@ public class DiagnosticCompilerTestFirTestdataTestGenerated extends AbstractDiag runTest("compiler/fir/analysis-tests/testData/resolve/propertyFromJavaPlusAssign.kt"); } + @Test + @TestMetadata("propertyGetterWithoutType.kt") + public void testPropertyGetterWithoutType() throws Exception { + runTest("compiler/fir/analysis-tests/testData/resolve/propertyGetterWithoutType.kt"); + } + @Test @TestMetadata("qualifierWithCompanion.kt") public void testQualifierWithCompanion() 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 3d7e375addf..ba4d215fa57 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 @@ -530,6 +530,12 @@ public class LLFirPreresolvedReversedDiagnosticCompilerFirTestDataTestGenerated runTest("compiler/fir/analysis-tests/testData/resolve/propertyFromJavaPlusAssign.kt"); } + @Test + @TestMetadata("propertyGetterWithoutType.kt") + public void testPropertyGetterWithoutType() throws Exception { + runTest("compiler/fir/analysis-tests/testData/resolve/propertyGetterWithoutType.kt"); + } + @Test @TestMetadata("qualifierWithCompanion.kt") public void testQualifierWithCompanion() throws Exception { diff --git a/compiler/fir/analysis-tests/legacy-fir-tests/tests-gen/org/jetbrains/kotlin/fir/LazyBodyIsNotTouchedTestGenerated.java b/compiler/fir/analysis-tests/legacy-fir-tests/tests-gen/org/jetbrains/kotlin/fir/LazyBodyIsNotTouchedTestGenerated.java index 21ae77b233f..dc0d18ed2f0 100644 --- a/compiler/fir/analysis-tests/legacy-fir-tests/tests-gen/org/jetbrains/kotlin/fir/LazyBodyIsNotTouchedTestGenerated.java +++ b/compiler/fir/analysis-tests/legacy-fir-tests/tests-gen/org/jetbrains/kotlin/fir/LazyBodyIsNotTouchedTestGenerated.java @@ -449,6 +449,11 @@ public class LazyBodyIsNotTouchedTestGenerated extends AbstractLazyBodyIsNotTouc runTest("compiler/fir/analysis-tests/testData/resolve/propertyFromJavaPlusAssign.kt"); } + @TestMetadata("propertyGetterWithoutType.kt") + public void testPropertyGetterWithoutType() throws Exception { + runTest("compiler/fir/analysis-tests/testData/resolve/propertyGetterWithoutType.kt"); + } + @TestMetadata("qualifierWithCompanion.kt") public void testQualifierWithCompanion() throws Exception { runTest("compiler/fir/analysis-tests/testData/resolve/qualifierWithCompanion.kt"); diff --git a/compiler/fir/analysis-tests/testData/resolve/propertyGetterWithoutType.fir.txt b/compiler/fir/analysis-tests/testData/resolve/propertyGetterWithoutType.fir.txt new file mode 100644 index 00000000000..dd971c837b6 --- /dev/null +++ b/compiler/fir/analysis-tests/testData/resolve/propertyGetterWithoutType.fir.txt @@ -0,0 +1,9 @@ +FILE: propertyGetterWithoutType.kt + public final val prop: + public get(): { + local final fun smth(s: R|kotlin/String|): R|kotlin/Int| { + ^smth Int(1) + } + + ^ R|/smth|(String(awd)) + } diff --git a/compiler/fir/analysis-tests/testData/resolve/propertyGetterWithoutType.kt b/compiler/fir/analysis-tests/testData/resolve/propertyGetterWithoutType.kt new file mode 100644 index 00000000000..c2ccbfd4b45 --- /dev/null +++ b/compiler/fir/analysis-tests/testData/resolve/propertyGetterWithoutType.kt @@ -0,0 +1,6 @@ +// ISSUE: KT-59649 +val prop + get() { + fun smth(s: String) = 1 + return smth("awd") + } 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 723ac4186e6..9e09d925d19 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 @@ -530,6 +530,12 @@ public class FirLightTreeDiagnosticsTestGenerated extends AbstractFirLightTreeDi runTest("compiler/fir/analysis-tests/testData/resolve/propertyFromJavaPlusAssign.kt"); } + @Test + @TestMetadata("propertyGetterWithoutType.kt") + public void testPropertyGetterWithoutType() throws Exception { + runTest("compiler/fir/analysis-tests/testData/resolve/propertyGetterWithoutType.kt"); + } + @Test @TestMetadata("qualifierWithCompanion.kt") public void testQualifierWithCompanion() 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 c52426fd0fb..3c31f3239e4 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 @@ -530,6 +530,12 @@ public class FirPsiDiagnosticTestGenerated extends AbstractFirPsiDiagnosticTest runTest("compiler/fir/analysis-tests/testData/resolve/propertyFromJavaPlusAssign.kt"); } + @Test + @TestMetadata("propertyGetterWithoutType.kt") + public void testPropertyGetterWithoutType() throws Exception { + runTest("compiler/fir/analysis-tests/testData/resolve/propertyGetterWithoutType.kt"); + } + @Test @TestMetadata("qualifierWithCompanion.kt") public void testQualifierWithCompanion() throws Exception { diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/body/resolve/FirDeclarationsResolveTransformer.kt b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/body/resolve/FirDeclarationsResolveTransformer.kt index cb4d2b22ee2..15416314263 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/body/resolve/FirDeclarationsResolveTransformer.kt +++ b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/body/resolve/FirDeclarationsResolveTransformer.kt @@ -656,7 +656,7 @@ open class FirDeclarationsResolveTransformer( val body = result.body if (result.returnTypeRef is FirImplicitTypeRef) { val simpleFunction = function as? FirSimpleFunction - val returnExpression = (body?.statements?.single() as? FirReturnExpression)?.result + val returnExpression = (body?.statements?.singleOrNull() as? FirReturnExpression)?.result val returnTypeRef = if (returnExpression?.typeRef is FirResolvedTypeRef) { returnExpression.resultType.approximateDeclarationType( session,