From a17fc51b9f846ad8e7ddfe76ca8fc17ea31a4d26 Mon Sep 17 00:00:00 2001 From: Simon Ogorodnik Date: Sat, 3 Sep 2022 13:52:12 +0200 Subject: [PATCH] Fix receiver inconsistency when builder inference restriction disabled In 154e53c701ed1481315af04d822ab0587e2ec3e8 update of extensionReceiverArgument in resolvedCall was accidentally moved into language feature dependant block --- ...CompilerTestFE10TestdataTestGenerated.java | 6 +++++ ...irOldFrontendDiagnosticsTestGenerated.java | 6 +++++ ...DiagnosticsWithLightTreeTestGenerated.java | 6 +++++ .../calls/components/ResolutionParts.kt | 26 +++++++++---------- ...ferenceRestrictionReceiverInconsistency.kt | 15 +++++++++++ .../test/runners/DiagnosticTestGenerated.java | 6 +++++ 6 files changed, 52 insertions(+), 13 deletions(-) create mode 100644 compiler/testData/diagnostics/tests/inference/builderInference/noBuilderInferenceRestrictionReceiverInconsistency.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 2a2b9e56aab82..ed26ee387feb6 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 @@ -14417,6 +14417,12 @@ public void testMultiLambdaRestrictionDisabled() throws Exception { runTest("compiler/testData/diagnostics/tests/inference/builderInference/multiLambdaRestrictionDisabled.kt"); } + @Test + @TestMetadata("noBuilderInferenceRestrictionReceiverInconsistency.kt") + public void testNoBuilderInferenceRestrictionReceiverInconsistency() throws Exception { + runTest("compiler/testData/diagnostics/tests/inference/builderInference/noBuilderInferenceRestrictionReceiverInconsistency.kt"); + } + @Test @TestMetadata("simpleLambdaInCallWithAnotherLambdaWithBuilderInference.kt") public void testSimpleLambdaInCallWithAnotherLambdaWithBuilderInference() 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 66eb30c4411fe..cb6d97de96bda 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 @@ -14417,6 +14417,12 @@ public void testMultiLambdaRestrictionDisabled() throws Exception { runTest("compiler/testData/diagnostics/tests/inference/builderInference/multiLambdaRestrictionDisabled.kt"); } + @Test + @TestMetadata("noBuilderInferenceRestrictionReceiverInconsistency.kt") + public void testNoBuilderInferenceRestrictionReceiverInconsistency() throws Exception { + runTest("compiler/testData/diagnostics/tests/inference/builderInference/noBuilderInferenceRestrictionReceiverInconsistency.kt"); + } + @Test @TestMetadata("simpleLambdaInCallWithAnotherLambdaWithBuilderInference.kt") public void testSimpleLambdaInCallWithAnotherLambdaWithBuilderInference() 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 bba007217d9e2..0fbb189c7e75a 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 @@ -14417,6 +14417,12 @@ public void testMultiLambdaRestrictionDisabled() throws Exception { runTest("compiler/testData/diagnostics/tests/inference/builderInference/multiLambdaRestrictionDisabled.kt"); } + @Test + @TestMetadata("noBuilderInferenceRestrictionReceiverInconsistency.kt") + public void testNoBuilderInferenceRestrictionReceiverInconsistency() throws Exception { + runTest("compiler/testData/diagnostics/tests/inference/builderInference/noBuilderInferenceRestrictionReceiverInconsistency.kt"); + } + @Test @TestMetadata("simpleLambdaInCallWithAnotherLambdaWithBuilderInference.kt") public void testSimpleLambdaInCallWithAnotherLambdaWithBuilderInference() throws Exception { diff --git a/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/components/ResolutionParts.kt b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/components/ResolutionParts.kt index 686d00a7e53b2..7d38f503db098 100644 --- a/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/components/ResolutionParts.kt +++ b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/components/ResolutionParts.kt @@ -664,23 +664,23 @@ internal object CheckReceivers : ResolutionPart() { ) 1 -> { + var extensionReceiverArgument = resolvedCall.extensionReceiverArgument + if (extensionReceiverArgument == null) { + extensionReceiverArgument = chooseExtensionReceiverCandidate() ?: return + resolvedCall.extensionReceiverArgument = extensionReceiverArgument + } val checkBuilderInferenceRestriction = !callComponents.languageVersionSettings .supportsFeature(LanguageFeature.NoBuilderInferenceWithoutAnnotationRestriction) - if (checkBuilderInferenceRestriction) { - var extensionReceiverArgument = resolvedCall.extensionReceiverArgument - if (extensionReceiverArgument == null) { - extensionReceiverArgument = chooseExtensionReceiverCandidate() ?: return - resolvedCall.extensionReceiverArgument = extensionReceiverArgument - } - if (extensionReceiverArgument.receiver.receiverValue.type is StubTypeForBuilderInference) { - addDiagnostic( - StubBuilderInferenceReceiver( - extensionReceiverArgument, - candidateDescriptor.extensionReceiverParameter!! - ) + if (checkBuilderInferenceRestriction && + extensionReceiverArgument.receiver.receiverValue.type is StubTypeForBuilderInference + ) { + addDiagnostic( + StubBuilderInferenceReceiver( + extensionReceiverArgument, + candidateDescriptor.extensionReceiverParameter!! ) - } + ) } checkReceiver( resolvedCall.extensionReceiverArgument, diff --git a/compiler/testData/diagnostics/tests/inference/builderInference/noBuilderInferenceRestrictionReceiverInconsistency.kt b/compiler/testData/diagnostics/tests/inference/builderInference/noBuilderInferenceRestrictionReceiverInconsistency.kt new file mode 100644 index 0000000000000..ed20a4017ae8f --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/builderInference/noBuilderInferenceRestrictionReceiverInconsistency.kt @@ -0,0 +1,15 @@ +// FIR_IDENTICAL +// SKIP_TXT +// WITH_STDLIB +// LANGUAGE: +NoBuilderInferenceWithoutAnnotationRestriction + +class A +class B + +var B.foo: Boolean + get() = true + set(value) {} + +private fun A.bar(b: B) { + b.foo = true +} \ No newline at end of file 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 f3936cfd8627a..8d545fa4f6f5e 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 @@ -14423,6 +14423,12 @@ public void testMultiLambdaRestrictionDisabled() throws Exception { runTest("compiler/testData/diagnostics/tests/inference/builderInference/multiLambdaRestrictionDisabled.kt"); } + @Test + @TestMetadata("noBuilderInferenceRestrictionReceiverInconsistency.kt") + public void testNoBuilderInferenceRestrictionReceiverInconsistency() throws Exception { + runTest("compiler/testData/diagnostics/tests/inference/builderInference/noBuilderInferenceRestrictionReceiverInconsistency.kt"); + } + @Test @TestMetadata("simpleLambdaInCallWithAnotherLambdaWithBuilderInference.kt") public void testSimpleLambdaInCallWithAnotherLambdaWithBuilderInference() throws Exception {