From 994040c91c1a2827fc176090f7dd0fa81b3f68c5 Mon Sep 17 00:00:00 2001 From: "Denis.Zharkov" Date: Tue, 2 Nov 2021 15:36:14 +0300 Subject: [PATCH] FIR: Support invoke convention on super-qualified calls --- ...gnosisCompilerTestFE10TestdataTestGenerated.java | 6 ++++++ .../FirOldFrontendDiagnosticsTestGenerated.java | 6 ++++++ ...ontendDiagnosticsWithLightTreeTestGenerated.java | 6 ++++++ .../calls/tower/FirInvokeResolveTowerExtension.kt | 13 +++++++++++++ .../fir/resolve/calls/tower/FirTowerResolver.kt | 1 + .../diagnostics/tests/resolve/superInvoke.kt | 13 +++++++++++++ .../test/runners/DiagnosticTestGenerated.java | 6 ++++++ 7 files changed, 51 insertions(+) create mode 100644 compiler/testData/diagnostics/tests/resolve/superInvoke.kt diff --git a/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/DiagnosisCompilerTestFE10TestdataTestGenerated.java b/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/DiagnosisCompilerTestFE10TestdataTestGenerated.java index ebecbcf4df4..0fceafd0c97 100644 --- a/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/DiagnosisCompilerTestFE10TestdataTestGenerated.java +++ b/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/DiagnosisCompilerTestFE10TestdataTestGenerated.java @@ -24509,6 +24509,12 @@ public class DiagnosisCompilerTestFE10TestdataTestGenerated extends AbstractDiag runTest("compiler/testData/diagnostics/tests/resolve/resolveWithoutGenerics.kt"); } + @Test + @TestMetadata("superInvoke.kt") + public void testSuperInvoke() throws Exception { + runTest("compiler/testData/diagnostics/tests/resolve/superInvoke.kt"); + } + @Test @TestMetadata("typeParameterInDefaultValueInLocalFunction.kt") public void testTypeParameterInDefaultValueInLocalFunction() throws Exception { diff --git a/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendDiagnosticsTestGenerated.java b/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendDiagnosticsTestGenerated.java index 21eb59d385a..3d24303506c 100644 --- a/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendDiagnosticsTestGenerated.java +++ b/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendDiagnosticsTestGenerated.java @@ -24509,6 +24509,12 @@ public class FirOldFrontendDiagnosticsTestGenerated extends AbstractFirDiagnosti runTest("compiler/testData/diagnostics/tests/resolve/resolveWithoutGenerics.kt"); } + @Test + @TestMetadata("superInvoke.kt") + public void testSuperInvoke() throws Exception { + runTest("compiler/testData/diagnostics/tests/resolve/superInvoke.kt"); + } + @Test @TestMetadata("typeParameterInDefaultValueInLocalFunction.kt") public void testTypeParameterInDefaultValueInLocalFunction() throws Exception { diff --git a/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendDiagnosticsWithLightTreeTestGenerated.java b/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendDiagnosticsWithLightTreeTestGenerated.java index 2c52346ed74..2a1da1c36a9 100644 --- a/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendDiagnosticsWithLightTreeTestGenerated.java +++ b/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendDiagnosticsWithLightTreeTestGenerated.java @@ -24509,6 +24509,12 @@ public class FirOldFrontendDiagnosticsWithLightTreeTestGenerated extends Abstrac runTest("compiler/testData/diagnostics/tests/resolve/resolveWithoutGenerics.kt"); } + @Test + @TestMetadata("superInvoke.kt") + public void testSuperInvoke() throws Exception { + runTest("compiler/testData/diagnostics/tests/resolve/superInvoke.kt"); + } + @Test @TestMetadata("typeParameterInDefaultValueInLocalFunction.kt") public void testTypeParameterInDefaultValueInLocalFunction() 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 c1c78a37922..964794d05e9 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 @@ -7,6 +7,7 @@ package org.jetbrains.kotlin.fir.resolve.calls.tower import org.jetbrains.kotlin.fir.declarations.FirTypedDeclaration import org.jetbrains.kotlin.fir.expressions.FirExpression +import org.jetbrains.kotlin.fir.expressions.FirQualifiedAccessExpression import org.jetbrains.kotlin.fir.expressions.FirResolvedQualifier import org.jetbrains.kotlin.fir.expressions.builder.FirPropertyAccessExpressionBuilder import org.jetbrains.kotlin.fir.resolve.* @@ -53,6 +54,18 @@ internal class FirInvokeResolveTowerExtension( } } + fun enqueueResolveTasksForSuperReceiver(info: CallInfo, receiver: FirQualifiedAccessExpression) { + if (info.callKind != CallKind.Function) return + val invokeReceiverVariableInfo = info.replaceWithVariableAccess() + enqueueInvokeReceiverTask( + info, + invokeReceiverVariableInfo, + invokeBuiltinExtensionMode = false + ) { + it.runResolverForSuperReceiver(invokeReceiverVariableInfo, receiver) + } + } + fun enqueueResolveTasksForExpressionReceiver(info: CallInfo, receiver: FirExpression) { if (info.callKind != CallKind.Function) return enqueueBothInvokeReceiverTasks( diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/tower/FirTowerResolver.kt b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/tower/FirTowerResolver.kt index 0b77cb7353f..f9159133449 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/tower/FirTowerResolver.kt +++ b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/tower/FirTowerResolver.kt @@ -66,6 +66,7 @@ class FirTowerResolver( if (receiver is FirQualifiedAccessExpression) { if (receiver.calleeReference is FirSuperReference) { manager.enqueueResolverTask { mainTask.runResolverForSuperReceiver(info, receiver) } + invokeResolveTowerExtension.enqueueResolveTasksForSuperReceiver(info, receiver) return } } diff --git a/compiler/testData/diagnostics/tests/resolve/superInvoke.kt b/compiler/testData/diagnostics/tests/resolve/superInvoke.kt new file mode 100644 index 00000000000..63c779c2cc2 --- /dev/null +++ b/compiler/testData/diagnostics/tests/resolve/superInvoke.kt @@ -0,0 +1,13 @@ +// FIR_IDENTICAL +// SKIP_TXT +// FILE: main.kt + +open class A { + protected open val x: (String) -> Boolean = { true } +} + +class B : A() { + override val x = { y: String -> + super.x(y) + } +} diff --git a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/DiagnosticTestGenerated.java b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/DiagnosticTestGenerated.java index d7112b05409..847acf3fac6 100644 --- a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/DiagnosticTestGenerated.java +++ b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/DiagnosticTestGenerated.java @@ -24521,6 +24521,12 @@ public class DiagnosticTestGenerated extends AbstractDiagnosticTest { runTest("compiler/testData/diagnostics/tests/resolve/resolveWithoutGenerics.kt"); } + @Test + @TestMetadata("superInvoke.kt") + public void testSuperInvoke() throws Exception { + runTest("compiler/testData/diagnostics/tests/resolve/superInvoke.kt"); + } + @Test @TestMetadata("typeParameterInDefaultValueInLocalFunction.kt") public void testTypeParameterInDefaultValueInLocalFunction() throws Exception {