From 393a5d6c14b60f023ddb4d7e68f53098f8be8a44 Mon Sep 17 00:00:00 2001 From: Kirill Rakhman Date: Tue, 29 Aug 2023 14:33:22 +0200 Subject: [PATCH] [FIR] Fix IAE in TYPECHECKER_HAS_RUN_INTO_RECURSIVE_PROBLEM IllegalArgumentException: class org.jetbrains.kotlin.psi.KtLambdaArgument is not a subtype of class org.jetbrains.kotlin.psi.KtExpression for factory TYPECHECKER_HAS_RUN_INTO_RECURSIVE_PROBLEM was reported when TYPECHECKER_HAS_RUN_INTO_RECURSIVE_PROBLEM was reported on a FirLambdaArgumentExpression, report it on its `expression` instead. #KT-60380 Fixed --- .../DiagnosticCompilerTestFirTestdataTestGenerated.java | 6 ++++++ ...versedDiagnosticCompilerFirTestDataTestGenerated.java | 6 ++++++ .../diagnostics/recursiveProblemWithSyntaxError.fir.txt | 9 +++++++++ .../diagnostics/recursiveProblemWithSyntaxError.kt | 3 +++ .../runners/FirLightTreeDiagnosticsTestGenerated.java | 6 ++++++ .../test/runners/FirPsiDiagnosticTestGenerated.java | 6 ++++++ .../checkers/expression/FirRecursiveProblemChecker.kt | 5 ++++- 7 files changed, 40 insertions(+), 1 deletion(-) create mode 100644 compiler/fir/analysis-tests/testData/resolve/diagnostics/recursiveProblemWithSyntaxError.fir.txt create mode 100644 compiler/fir/analysis-tests/testData/resolve/diagnostics/recursiveProblemWithSyntaxError.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 6775378c357..8df5870a80e 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 @@ -1925,6 +1925,12 @@ public class DiagnosticCompilerTestFirTestdataTestGenerated extends AbstractDiag runTest("compiler/fir/analysis-tests/testData/resolve/diagnostics/qualifiedSupertypeExtendedByOtherSupertype.kt"); } + @Test + @TestMetadata("recursiveProblemWithSyntaxError.kt") + public void testRecursiveProblemWithSyntaxError() throws Exception { + runTest("compiler/fir/analysis-tests/testData/resolve/diagnostics/recursiveProblemWithSyntaxError.kt"); + } + @Test @TestMetadata("redundantModifier.kt") public void testRedundantModifier() 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 2365129b6d9..58e069da378 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 @@ -1925,6 +1925,12 @@ public class LLFirPreresolvedReversedDiagnosticCompilerFirTestDataTestGenerated runTest("compiler/fir/analysis-tests/testData/resolve/diagnostics/qualifiedSupertypeExtendedByOtherSupertype.kt"); } + @Test + @TestMetadata("recursiveProblemWithSyntaxError.kt") + public void testRecursiveProblemWithSyntaxError() throws Exception { + runTest("compiler/fir/analysis-tests/testData/resolve/diagnostics/recursiveProblemWithSyntaxError.kt"); + } + @Test @TestMetadata("redundantModifier.kt") public void testRedundantModifier() throws Exception { diff --git a/compiler/fir/analysis-tests/testData/resolve/diagnostics/recursiveProblemWithSyntaxError.fir.txt b/compiler/fir/analysis-tests/testData/resolve/diagnostics/recursiveProblemWithSyntaxError.fir.txt new file mode 100644 index 00000000000..8e83771c620 --- /dev/null +++ b/compiler/fir/analysis-tests/testData/resolve/diagnostics/recursiveProblemWithSyntaxError.fir.txt @@ -0,0 +1,9 @@ +FILE: recursiveProblemWithSyntaxError.kt + public final val foo: = bar@fun (): { + ^ # + } + .R|SubstitutionOverride>#|(ERROR_EXPR(Argument is absent)).#(#( = @fun (): { + ^ R|/foo| + } + )) + public get(): diff --git a/compiler/fir/analysis-tests/testData/resolve/diagnostics/recursiveProblemWithSyntaxError.kt b/compiler/fir/analysis-tests/testData/resolve/diagnostics/recursiveProblemWithSyntaxError.kt new file mode 100644 index 00000000000..9910d05708d --- /dev/null +++ b/compiler/fir/analysis-tests/testData/resolve/diagnostics/recursiveProblemWithSyntaxError.kt @@ -0,0 +1,3 @@ +val foo = { bar }( + +val bar = { foo } 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 d2c6df82881..c020a99bca2 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 @@ -1925,6 +1925,12 @@ public class FirLightTreeDiagnosticsTestGenerated extends AbstractFirLightTreeDi runTest("compiler/fir/analysis-tests/testData/resolve/diagnostics/qualifiedSupertypeExtendedByOtherSupertype.kt"); } + @Test + @TestMetadata("recursiveProblemWithSyntaxError.kt") + public void testRecursiveProblemWithSyntaxError() throws Exception { + runTest("compiler/fir/analysis-tests/testData/resolve/diagnostics/recursiveProblemWithSyntaxError.kt"); + } + @Test @TestMetadata("redundantModifier.kt") public void testRedundantModifier() 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 9b6fd123255..33ed23116b0 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 @@ -1925,6 +1925,12 @@ public class FirPsiDiagnosticTestGenerated extends AbstractFirPsiDiagnosticTest runTest("compiler/fir/analysis-tests/testData/resolve/diagnostics/qualifiedSupertypeExtendedByOtherSupertype.kt"); } + @Test + @TestMetadata("recursiveProblemWithSyntaxError.kt") + public void testRecursiveProblemWithSyntaxError() throws Exception { + runTest("compiler/fir/analysis-tests/testData/resolve/diagnostics/recursiveProblemWithSyntaxError.kt"); + } + @Test @TestMetadata("redundantModifier.kt") public void testRedundantModifier() throws Exception { diff --git a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/expression/FirRecursiveProblemChecker.kt b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/expression/FirRecursiveProblemChecker.kt index 24134fe8e8e..c60d596fd21 100644 --- a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/expression/FirRecursiveProblemChecker.kt +++ b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/expression/FirRecursiveProblemChecker.kt @@ -13,9 +13,11 @@ import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors import org.jetbrains.kotlin.fir.diagnostics.ConeSimpleDiagnostic import org.jetbrains.kotlin.fir.diagnostics.DiagnosticKind import org.jetbrains.kotlin.fir.expressions.FirExpression +import org.jetbrains.kotlin.fir.expressions.FirLambdaArgumentExpression import org.jetbrains.kotlin.fir.expressions.FirStatement import org.jetbrains.kotlin.fir.expressions.impl.FirNoReceiverExpression import org.jetbrains.kotlin.fir.types.* +import org.jetbrains.kotlin.psi.KtLambdaArgument object FirRecursiveProblemChecker : FirBasicExpressionChecker() { override fun check(expression: FirStatement, context: CheckerContext, reporter: DiagnosticReporter) { @@ -29,7 +31,8 @@ object FirRecursiveProblemChecker : FirBasicExpressionChecker() { fun checkConeType(coneType: ConeKotlinType?) { if (coneType is ConeErrorType && (coneType.diagnostic as? ConeSimpleDiagnostic)?.kind == DiagnosticKind.RecursionInImplicitTypes) { - reporter.reportOn(expression.source, FirErrors.TYPECHECKER_HAS_RUN_INTO_RECURSIVE_PROBLEM, context) + val source = ((expression as? FirLambdaArgumentExpression)?.expression ?: expression).source + reporter.reportOn(source, FirErrors.TYPECHECKER_HAS_RUN_INTO_RECURSIVE_PROBLEM, context) } else if (coneType is ConeClassLikeType) { for (typeArgument in coneType.typeArguments) { checkConeType(typeArgument.type)