From f797ee78035f5a301b738dd6416219503554efe4 Mon Sep 17 00:00:00 2001 From: Victor Petukhov Date: Tue, 9 Feb 2021 12:58:53 +0300 Subject: [PATCH] Substitute captured types with inner intersection one (NewTypeSubstitutor) ^KT-44651 Fixed --- .../codegen/FirBlackBoxCodegenTestGenerated.java | 6 ++++++ .../inference/components/NewTypeSubstitutor.kt | 2 +- .../substituteIntersectionTypeInsideCapType.kt | 15 +++++++++++++++ .../codegen/BlackBoxCodegenTestGenerated.java | 6 ++++++ .../codegen/IrBlackBoxCodegenTestGenerated.java | 6 ++++++ .../codegen/LightAnalysisModeTestGenerated.java | 5 +++++ 6 files changed, 39 insertions(+), 1 deletion(-) create mode 100644 compiler/testData/codegen/box/inference/substituteIntersectionTypeInsideCapType.kt diff --git a/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/codegen/FirBlackBoxCodegenTestGenerated.java b/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/codegen/FirBlackBoxCodegenTestGenerated.java index 1da51faae4f..dc3a6dc19af 100644 --- a/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/codegen/FirBlackBoxCodegenTestGenerated.java +++ b/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/codegen/FirBlackBoxCodegenTestGenerated.java @@ -16666,6 +16666,12 @@ public class FirBlackBoxCodegenTestGenerated extends AbstractFirBlackBoxCodegenT runTest("compiler/testData/codegen/box/inference/specialCallsWithCallableReferences.kt"); } + @Test + @TestMetadata("substituteIntersectionTypeInsideCapType.kt") + public void testSubstituteIntersectionTypeInsideCapType() throws Exception { + runTest("compiler/testData/codegen/box/inference/substituteIntersectionTypeInsideCapType.kt"); + } + @Test @TestMetadata("subtypingOfIntersectionIltInsideFlexible.kt") public void testSubtypingOfIntersectionIltInsideFlexible() throws Exception { diff --git a/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/inference/components/NewTypeSubstitutor.kt b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/inference/components/NewTypeSubstitutor.kt index 9a7aed50205..8a795862d30 100644 --- a/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/inference/components/NewTypeSubstitutor.kt +++ b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/inference/components/NewTypeSubstitutor.kt @@ -105,7 +105,7 @@ interface NewTypeSubstitutor : TypeSubstitutorMarker { val substitutedInnerType = substitute(innerType, keepAnnotation, runCapturedChecks = false) if (substitutedInnerType != null) { - if (innerType is StubType || substitutedInnerType is StubType) { + if (innerType is StubType || substitutedInnerType is StubType || innerType.constructor is IntersectionTypeConstructor) { return NewCapturedType( capturedType.captureStatus, NewCapturedTypeConstructor( diff --git a/compiler/testData/codegen/box/inference/substituteIntersectionTypeInsideCapType.kt b/compiler/testData/codegen/box/inference/substituteIntersectionTypeInsideCapType.kt new file mode 100644 index 00000000000..ae86b03e105 --- /dev/null +++ b/compiler/testData/codegen/box/inference/substituteIntersectionTypeInsideCapType.kt @@ -0,0 +1,15 @@ +// TARGET_BACKEND: JVM +// TARGET_BACKEND: JVM_IR + +class X(val y: Any, val x: T) + +fun box(): String { + val num: Long = -10 + val num2: Int = 20 + val obj = if (true) + X(Any(), if (true) num else num2) + else + X(Any(), -25) + val f = obj.y + return "OK" +} diff --git a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/BlackBoxCodegenTestGenerated.java b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/BlackBoxCodegenTestGenerated.java index 422a0c5d6cb..c82a52bc9ba 100644 --- a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/BlackBoxCodegenTestGenerated.java +++ b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/BlackBoxCodegenTestGenerated.java @@ -16666,6 +16666,12 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest { runTest("compiler/testData/codegen/box/inference/specialCallsWithCallableReferences.kt"); } + @Test + @TestMetadata("substituteIntersectionTypeInsideCapType.kt") + public void testSubstituteIntersectionTypeInsideCapType() throws Exception { + runTest("compiler/testData/codegen/box/inference/substituteIntersectionTypeInsideCapType.kt"); + } + @Test @TestMetadata("subtypingOfIntersectionIltInsideFlexible.kt") public void testSubtypingOfIntersectionIltInsideFlexible() throws Exception { diff --git a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/IrBlackBoxCodegenTestGenerated.java b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/IrBlackBoxCodegenTestGenerated.java index 87555c2b540..21a799582d4 100644 --- a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/IrBlackBoxCodegenTestGenerated.java +++ b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/IrBlackBoxCodegenTestGenerated.java @@ -16666,6 +16666,12 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes runTest("compiler/testData/codegen/box/inference/specialCallsWithCallableReferences.kt"); } + @Test + @TestMetadata("substituteIntersectionTypeInsideCapType.kt") + public void testSubstituteIntersectionTypeInsideCapType() throws Exception { + runTest("compiler/testData/codegen/box/inference/substituteIntersectionTypeInsideCapType.kt"); + } + @Test @TestMetadata("subtypingOfIntersectionIltInsideFlexible.kt") public void testSubtypingOfIntersectionIltInsideFlexible() throws Exception { diff --git a/compiler/tests-gen/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java b/compiler/tests-gen/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java index 8c224ed249f..6150d21095b 100644 --- a/compiler/tests-gen/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java +++ b/compiler/tests-gen/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java @@ -13855,6 +13855,11 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes runTest("compiler/testData/codegen/box/inference/specialCallsWithCallableReferences.kt"); } + @TestMetadata("substituteIntersectionTypeInsideCapType.kt") + public void testSubstituteIntersectionTypeInsideCapType() throws Exception { + runTest("compiler/testData/codegen/box/inference/substituteIntersectionTypeInsideCapType.kt"); + } + @TestMetadata("subtypingOfIntersectionIltInsideFlexible.kt") public void testSubtypingOfIntersectionIltInsideFlexible() throws Exception { runTest("compiler/testData/codegen/box/inference/subtypingOfIntersectionIltInsideFlexible.kt");