From ce65d3c7b872e70ba751387565d7bc088343a167 Mon Sep 17 00:00:00 2001 From: Kirill Rakhman Date: Wed, 13 Sep 2023 12:08:36 +0200 Subject: [PATCH] [FIR] Set source on callee reference of implicit invoke receiver This fixes an IllegalArgumentException when a diagnostic was reported on it because no source was set. #KT-61829 Fixed --- ...gnosticCompilerTestFirTestdataTestGenerated.java | 6 ++++++ ...dDiagnosticCompilerFirTestDataTestGenerated.java | 6 ++++++ .../problems/incorrectGenericLambdaProperty.fir.txt | 13 +++++++++++++ .../problems/incorrectGenericLambdaProperty.kt | 5 +++++ .../FirLightTreeDiagnosticsTestGenerated.java | 6 ++++++ .../test/runners/FirPsiDiagnosticTestGenerated.java | 6 ++++++ .../calls/tower/FirInvokeResolveTowerExtension.kt | 5 +++-- 7 files changed, 45 insertions(+), 2 deletions(-) create mode 100644 compiler/fir/analysis-tests/testData/resolve/problems/incorrectGenericLambdaProperty.fir.txt create mode 100644 compiler/fir/analysis-tests/testData/resolve/problems/incorrectGenericLambdaProperty.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 8df5870a80e..be1518af4e6 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 @@ -3847,6 +3847,12 @@ public class DiagnosticCompilerTestFirTestdataTestGenerated extends AbstractDiag runTest("compiler/fir/analysis-tests/testData/resolve/problems/incompleteWhen.kt"); } + @Test + @TestMetadata("incorrectGenericLambdaProperty.kt") + public void testIncorrectGenericLambdaProperty() throws Exception { + runTest("compiler/fir/analysis-tests/testData/resolve/problems/incorrectGenericLambdaProperty.kt"); + } + @Test @TestMetadata("innerClassHierarchy.kt") public void testInnerClassHierarchy() 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 58e069da378..d36d0dec6be 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 @@ -3847,6 +3847,12 @@ public class LLFirPreresolvedReversedDiagnosticCompilerFirTestDataTestGenerated runTest("compiler/fir/analysis-tests/testData/resolve/problems/incompleteWhen.kt"); } + @Test + @TestMetadata("incorrectGenericLambdaProperty.kt") + public void testIncorrectGenericLambdaProperty() throws Exception { + runTest("compiler/fir/analysis-tests/testData/resolve/problems/incorrectGenericLambdaProperty.kt"); + } + @Test @TestMetadata("innerClassHierarchy.kt") public void testInnerClassHierarchy() throws Exception { diff --git a/compiler/fir/analysis-tests/testData/resolve/problems/incorrectGenericLambdaProperty.fir.txt b/compiler/fir/analysis-tests/testData/resolve/problems/incorrectGenericLambdaProperty.fir.txt new file mode 100644 index 00000000000..e0a37f5c9c0 --- /dev/null +++ b/compiler/fir/analysis-tests/testData/resolve/problems/incorrectGenericLambdaProperty.fir.txt @@ -0,0 +1,13 @@ +FILE: incorrectGenericLambdaProperty.kt + public final fun main(args: R|kotlin/Array|): R|kotlin/Unit| { + lval passIt: R|(ERROR CLASS: No type for parameter) -> ERROR CLASS: Symbol not found for T| = fun (: ): { + lval t: = R|/|.#() + ^ { + R|/t| + } + + } + + R|/passIt/passIt>#|<>.R|SubstitutionOverride>#|(Int(1)) + R|/passIt/passIt>#|<>.R|SubstitutionOverride>|(Int(1)) + } diff --git a/compiler/fir/analysis-tests/testData/resolve/problems/incorrectGenericLambdaProperty.kt b/compiler/fir/analysis-tests/testData/resolve/problems/incorrectGenericLambdaProperty.kt new file mode 100644 index 00000000000..7f308d2f112 --- /dev/null +++ b/compiler/fir/analysis-tests/testData/resolve/problems/incorrectGenericLambdaProperty.kt @@ -0,0 +1,5 @@ +fun main(args: Array) { + val passIt = { (t: T) -> t } + passIt(1) + passIt(1) +} 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 c020a99bca2..0ab565c789b 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 @@ -3847,6 +3847,12 @@ public class FirLightTreeDiagnosticsTestGenerated extends AbstractFirLightTreeDi runTest("compiler/fir/analysis-tests/testData/resolve/problems/incompleteWhen.kt"); } + @Test + @TestMetadata("incorrectGenericLambdaProperty.kt") + public void testIncorrectGenericLambdaProperty() throws Exception { + runTest("compiler/fir/analysis-tests/testData/resolve/problems/incorrectGenericLambdaProperty.kt"); + } + @Test @TestMetadata("innerClassHierarchy.kt") public void testInnerClassHierarchy() 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 33ed23116b0..9d6cb026519 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 @@ -3847,6 +3847,12 @@ public class FirPsiDiagnosticTestGenerated extends AbstractFirPsiDiagnosticTest runTest("compiler/fir/analysis-tests/testData/resolve/problems/incompleteWhen.kt"); } + @Test + @TestMetadata("incorrectGenericLambdaProperty.kt") + public void testIncorrectGenericLambdaProperty() throws Exception { + runTest("compiler/fir/analysis-tests/testData/resolve/problems/incorrectGenericLambdaProperty.kt"); + } + @Test @TestMetadata("innerClassHierarchy.kt") public void testInnerClassHierarchy() throws Exception { diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/tower/FirInvokeResolveTowerExtension.kt b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/tower/FirInvokeResolveTowerExtension.kt index 21543bf26f1..1114ce2b85f 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/tower/FirInvokeResolveTowerExtension.kt +++ b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/tower/FirInvokeResolveTowerExtension.kt @@ -304,8 +304,9 @@ private fun BodyResolveComponents.createExplicitReceiverForInvokeByCallable( symbol: FirCallableSymbol<*> ): FirExpression { return FirPropertyAccessExpressionBuilder().apply { + val fakeSource = info.fakeSourceForImplicitInvokeCallReceiver calleeReference = FirNamedReferenceWithCandidate( - null, + fakeSource, symbol.callableId.callableName, candidate ) @@ -321,7 +322,7 @@ private fun BodyResolveComponents.createExplicitReceiverForInvokeByCallable( if (candidate.currentApplicability == CandidateApplicability.K2_PROPERTY_AS_OPERATOR) { nonFatalDiagnostics.add(ConePropertyAsOperator(candidate.symbol as FirPropertySymbol)) } - source = info.fakeSourceForImplicitInvokeCallReceiver + source = fakeSource }.build().let { callCompleter.completeCall(it, ResolutionMode.ReceiverResolution) }.let {