From a04913a1971766347fb3f8ab1eb5166fa7f26fce Mon Sep 17 00:00:00 2001 From: Mikhail Glukhikh Date: Mon, 9 Aug 2021 12:19:49 +0300 Subject: [PATCH] FIR: use captureFromTypeParameterUpperBoundIfNeeded for argument types #KT-48161 Fixed --- .../intellij/WithSpeedSearch.fir.txt | 24 +++++++++++++++++++ .../intellij/WithSpeedSearch.kt | 10 ++++++++ .../runners/FirDiagnosticTestGenerated.java | 6 +++++ ...DiagnosticsWithLightTreeTestGenerated.java | 6 +++++ .../kotlin/fir/resolve/calls/Arguments.kt | 6 +++-- .../captureFromTypeParameterUpperBound.fir.kt | 4 ++-- ...nosisCompilerFirTestdataTestGenerated.java | 6 +++++ 7 files changed, 58 insertions(+), 4 deletions(-) create mode 100644 compiler/fir/analysis-tests/testData/resolveWithStdlib/intellij/WithSpeedSearch.fir.txt create mode 100644 compiler/fir/analysis-tests/testData/resolveWithStdlib/intellij/WithSpeedSearch.kt diff --git a/compiler/fir/analysis-tests/testData/resolveWithStdlib/intellij/WithSpeedSearch.fir.txt b/compiler/fir/analysis-tests/testData/resolveWithStdlib/intellij/WithSpeedSearch.fir.txt new file mode 100644 index 00000000000..4aa86f7c1ae --- /dev/null +++ b/compiler/fir/analysis-tests/testData/resolveWithStdlib/intellij/WithSpeedSearch.fir.txt @@ -0,0 +1,24 @@ +FILE: WithSpeedSearch.kt + public final class JList : R|kotlin/Any| { + public constructor(): R|JList| { + super() + } + + } + public final class ListSpeedSearch : R|kotlin/Any| { + public constructor(list: R|JList|): R|ListSpeedSearch| { + super() + } + + } + public final class XThreadsFramesView : R|kotlin/Any| { + public constructor(): R|XThreadsFramesView| { + super() + } + + private final fun |> R|J|.withSpeedSearch(): R|J| { + lval search: R|ListSpeedSearch| = R|/ListSpeedSearch.ListSpeedSearch|(this@R|/XThreadsFramesView.withSpeedSearch|) + ^withSpeedSearch this@R|/XThreadsFramesView.withSpeedSearch| + } + + } diff --git a/compiler/fir/analysis-tests/testData/resolveWithStdlib/intellij/WithSpeedSearch.kt b/compiler/fir/analysis-tests/testData/resolveWithStdlib/intellij/WithSpeedSearch.kt new file mode 100644 index 00000000000..2fe2530c157 --- /dev/null +++ b/compiler/fir/analysis-tests/testData/resolveWithStdlib/intellij/WithSpeedSearch.kt @@ -0,0 +1,10 @@ +class JList + +class ListSpeedSearch(list: JList) + +class XThreadsFramesView { + private fun J.withSpeedSearch(): J where J : JList<*> { + val search = ListSpeedSearch(this) + return this + } +} diff --git a/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirDiagnosticTestGenerated.java b/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirDiagnosticTestGenerated.java index e36200d3bea..b985c17715e 100644 --- a/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirDiagnosticTestGenerated.java +++ b/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirDiagnosticTestGenerated.java @@ -5056,6 +5056,12 @@ public class FirDiagnosticTestGenerated extends AbstractFirDiagnosticTest { public void testUastPatterns() throws Exception { runTest("compiler/fir/analysis-tests/testData/resolveWithStdlib/intellij/UastPatterns.kt"); } + + @Test + @TestMetadata("WithSpeedSearch.kt") + public void testWithSpeedSearch() throws Exception { + runTest("compiler/fir/analysis-tests/testData/resolveWithStdlib/intellij/WithSpeedSearch.kt"); + } } @Nested diff --git a/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirDiagnosticsWithLightTreeTestGenerated.java b/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirDiagnosticsWithLightTreeTestGenerated.java index 850b0ca91fb..c4f0faed261 100644 --- a/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirDiagnosticsWithLightTreeTestGenerated.java +++ b/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirDiagnosticsWithLightTreeTestGenerated.java @@ -5056,6 +5056,12 @@ public class FirDiagnosticsWithLightTreeTestGenerated extends AbstractFirDiagnos public void testUastPatterns() throws Exception { runTest("compiler/fir/analysis-tests/testData/resolveWithStdlib/intellij/UastPatterns.kt"); } + + @Test + @TestMetadata("WithSpeedSearch.kt") + public void testWithSpeedSearch() throws Exception { + runTest("compiler/fir/analysis-tests/testData/resolveWithStdlib/intellij/WithSpeedSearch.kt"); + } } @Nested diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/Arguments.kt b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/Arguments.kt index fd4f80b919e..4792cdbddf0 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/Arguments.kt +++ b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/Arguments.kt @@ -31,7 +31,6 @@ import org.jetbrains.kotlin.resolve.calls.inference.ConstraintSystemBuilder import org.jetbrains.kotlin.resolve.calls.inference.addSubtypeConstraintIfCompatible import org.jetbrains.kotlin.resolve.calls.inference.model.SimpleConstraintSystemConstraintPosition import org.jetbrains.kotlin.types.AbstractTypeChecker -import org.jetbrains.kotlin.types.SmartcastStability import org.jetbrains.kotlin.types.model.CaptureStatus import org.jetbrains.kotlin.types.model.TypeSystemCommonSuperTypesContext import org.jetbrains.kotlin.utils.addToStdlib.runIf @@ -347,7 +346,7 @@ fun isArgumentTypeMismatchDueToNullability( private fun checkApplicabilityForArgumentType( csBuilder: ConstraintSystemBuilder, argument: FirExpression, - argumentType: ConeKotlinType, + argumentTypeBeforeCapturing: ConeKotlinType, expectedType: ConeKotlinType?, position: SimpleConstraintSystemConstraintPosition, isReceiver: Boolean, @@ -357,6 +356,9 @@ private fun checkApplicabilityForArgumentType( ) { if (expectedType == null) return + // todo run this approximation only once for call + val argumentType = captureFromTypeParameterUpperBoundIfNeeded(argumentTypeBeforeCapturing, expectedType, context.session) + fun subtypeError(actualExpectedType: ConeKotlinType): ResolutionDiagnostic { if (argument.isNullLiteral && actualExpectedType.nullability == ConeNullability.NOT_NULL) { return NullForNotNullType(argument) diff --git a/compiler/testData/diagnostics/tests/inference/capturedTypes/captureFromTypeParameterUpperBound.fir.kt b/compiler/testData/diagnostics/tests/inference/capturedTypes/captureFromTypeParameterUpperBound.fir.kt index a9c9bf21908..65b618ee02c 100644 --- a/compiler/testData/diagnostics/tests/inference/capturedTypes/captureFromTypeParameterUpperBound.fir.kt +++ b/compiler/testData/diagnostics/tests/inference/capturedTypes/captureFromTypeParameterUpperBound.fir.kt @@ -1,8 +1,8 @@ interface Inv fun > foo(x: X, y: Y) { - val rX = bar(x) - rX.length + val rX = bar(x) + rX.length val rY = bar(y) rY.length diff --git a/idea/idea-frontend-fir/idea-fir-low-level-api/tests/org/jetbrains/kotlin/idea/fir/low/level/api/diagnostic/compiler/based/DiagnosisCompilerFirTestdataTestGenerated.java b/idea/idea-frontend-fir/idea-fir-low-level-api/tests/org/jetbrains/kotlin/idea/fir/low/level/api/diagnostic/compiler/based/DiagnosisCompilerFirTestdataTestGenerated.java index c0003db71ee..0a1ea3d0793 100644 --- a/idea/idea-frontend-fir/idea-fir-low-level-api/tests/org/jetbrains/kotlin/idea/fir/low/level/api/diagnostic/compiler/based/DiagnosisCompilerFirTestdataTestGenerated.java +++ b/idea/idea-frontend-fir/idea-fir-low-level-api/tests/org/jetbrains/kotlin/idea/fir/low/level/api/diagnostic/compiler/based/DiagnosisCompilerFirTestdataTestGenerated.java @@ -5056,6 +5056,12 @@ public class DiagnosisCompilerFirTestdataTestGenerated extends AbstractDiagnosis public void testUastPatterns() throws Exception { runTest("compiler/fir/analysis-tests/testData/resolveWithStdlib/intellij/UastPatterns.kt"); } + + @Test + @TestMetadata("WithSpeedSearch.kt") + public void testWithSpeedSearch() throws Exception { + runTest("compiler/fir/analysis-tests/testData/resolveWithStdlib/intellij/WithSpeedSearch.kt"); + } } @Nested