K2: fix an exception during function resolve #KT-59649 Fixed
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 96a1fc0..97b84f8 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
@@ -531,6 +531,12 @@
         }
 
         @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 {
             runTest("compiler/fir/analysis-tests/testData/resolve/qualifierWithCompanion.kt");
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 3d7e375..ba4d215 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
@@ -531,6 +531,12 @@
         }
 
         @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 {
             runTest("compiler/fir/analysis-tests/testData/resolve/qualifierWithCompanion.kt");
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 21ae77b..dc0d18e 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 @@
         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 0000000..dd971c8
--- /dev/null
+++ b/compiler/fir/analysis-tests/testData/resolve/propertyGetterWithoutType.fir.txt
@@ -0,0 +1,9 @@
+FILE: propertyGetterWithoutType.kt
+    public final val prop: <ERROR TYPE REF: empty body>
+        public get(): <ERROR TYPE REF: empty body> {
+            local final fun smth(s: R|kotlin/String|): R|kotlin/Int| {
+                ^smth Int(1)
+            }
+
+            ^ R|<local>/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 0000000..c2ccbfd
--- /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 723ac41..9e09d92 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
@@ -531,6 +531,12 @@
         }
 
         @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 {
             runTest("compiler/fir/analysis-tests/testData/resolve/qualifierWithCompanion.kt");
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 c52426f..3c31f32 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
@@ -531,6 +531,12 @@
         }
 
         @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 {
             runTest("compiler/fir/analysis-tests/testData/resolve/qualifierWithCompanion.kt");
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 cb4d2b2..1541631 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 @@
         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,