From 1b8222730898c04da47af2c9a18df82bb9c03225 Mon Sep 17 00:00:00 2001 From: Victor Petukhov Date: Tue, 8 Jun 2021 14:22:39 +0300 Subject: [PATCH] Don't do new captured type specific checks for old ones in the type checker ^KT-47143 Fixed --- .../FirOldFrontendDiagnosticsTestGenerated.java | 6 ++++++ ...ndDiagnosticsWithLightTreeTestGenerated.java | 6 ++++++ .../kotlin/fir/types/ConeInferenceContext.kt | 2 ++ .../kotlin/fir/types/ConeTypeContext.kt | 2 ++ .../kotlin/ir/types/IrTypeSystemContext.kt | 2 ++ ...ckNewCapturedTypeSpecificChecksForOldOnes.kt | 14 ++++++++++++++ ...kNewCapturedTypeSpecificChecksForOldOnes.txt | 17 +++++++++++++++++ .../test/runners/DiagnosticTestGenerated.java | 6 ++++++ .../kotlin/types/AbstractTypeChecker.kt | 5 +++-- .../kotlin/types/model/TypeSystemContext.kt | 1 + .../types/checker/ClassicTypeSystemContext.kt | 3 +++ 11 files changed, 62 insertions(+), 2 deletions(-) create mode 100644 compiler/testData/diagnostics/tests/inference/capturedTypes/dontCheckNewCapturedTypeSpecificChecksForOldOnes.kt create mode 100644 compiler/testData/diagnostics/tests/inference/capturedTypes/dontCheckNewCapturedTypeSpecificChecksForOldOnes.txt 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 bab5aaf4e18..8845304e298 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 @@ -12944,6 +12944,12 @@ public class FirOldFrontendDiagnosticsTestGenerated extends AbstractFirDiagnosti runTest("compiler/testData/diagnostics/tests/inference/capturedTypes/capturingFromArgumentOfFlexibleType.kt"); } + @Test + @TestMetadata("dontCheckNewCapturedTypeSpecificChecksForOldOnes.kt") + public void testDontCheckNewCapturedTypeSpecificChecksForOldOnes() throws Exception { + runTest("compiler/testData/diagnostics/tests/inference/capturedTypes/dontCheckNewCapturedTypeSpecificChecksForOldOnes.kt"); + } + @Test @TestMetadata("expectedTypeMismatchWithInVariance.kt") public void testExpectedTypeMismatchWithInVariance() 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 b9795108e5a..49e4f497292 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 @@ -12944,6 +12944,12 @@ public class FirOldFrontendDiagnosticsWithLightTreeTestGenerated extends Abstrac runTest("compiler/testData/diagnostics/tests/inference/capturedTypes/capturingFromArgumentOfFlexibleType.kt"); } + @Test + @TestMetadata("dontCheckNewCapturedTypeSpecificChecksForOldOnes.kt") + public void testDontCheckNewCapturedTypeSpecificChecksForOldOnes() throws Exception { + runTest("compiler/testData/diagnostics/tests/inference/capturedTypes/dontCheckNewCapturedTypeSpecificChecksForOldOnes.kt"); + } + @Test @TestMetadata("expectedTypeMismatchWithInVariance.kt") public void testExpectedTypeMismatchWithInVariance() throws Exception { diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/types/ConeInferenceContext.kt b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/types/ConeInferenceContext.kt index 43bf6cab1b9..be58aabee4a 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/types/ConeInferenceContext.kt +++ b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/types/ConeInferenceContext.kt @@ -358,6 +358,8 @@ interface ConeInferenceContext : TypeSystemInferenceExtensionContext, ConeTypeCo return this.captureStatus } + override fun CapturedTypeMarker.isOldCapturedType(): Boolean = false + override fun TypeConstructorMarker.isCapturedTypeConstructor(): Boolean { return this is ConeCapturedTypeConstructor } diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/types/ConeTypeContext.kt b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/types/ConeTypeContext.kt index 9f6c818b92f..66d48256b72 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/types/ConeTypeContext.kt +++ b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/types/ConeTypeContext.kt @@ -157,6 +157,8 @@ interface ConeTypeContext : TypeSystemContext, TypeSystemOptimizationContext, Ty return this.captureStatus } + override fun CapturedTypeMarker.isOldCapturedType(): Boolean = false + override fun CapturedTypeConstructorMarker.projection(): TypeArgumentMarker { require(this is ConeCapturedTypeConstructor) return this.projection diff --git a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/types/IrTypeSystemContext.kt b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/types/IrTypeSystemContext.kt index 1c6f29a0af8..830f1f12757 100644 --- a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/types/IrTypeSystemContext.kt +++ b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/types/IrTypeSystemContext.kt @@ -106,6 +106,8 @@ interface IrTypeSystemContext : TypeSystemContext, TypeSystemCommonSuperTypesCon override fun CapturedTypeMarker.captureStatus(): CaptureStatus = (this as IrCapturedType).captureStatus + override fun CapturedTypeMarker.isOldCapturedType(): Boolean = false + override fun CapturedTypeConstructorMarker.projection(): TypeArgumentMarker = (this as IrCapturedType.Constructor).argument diff --git a/compiler/testData/diagnostics/tests/inference/capturedTypes/dontCheckNewCapturedTypeSpecificChecksForOldOnes.kt b/compiler/testData/diagnostics/tests/inference/capturedTypes/dontCheckNewCapturedTypeSpecificChecksForOldOnes.kt new file mode 100644 index 00000000000..2445c2ca19a --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/capturedTypes/dontCheckNewCapturedTypeSpecificChecksForOldOnes.kt @@ -0,0 +1,14 @@ +// FIR_IDENTICAL +// WITH_RUNTIME +// KT-47143 + +interface Container + +interface ContainerType> + +fun doGet(ep: ContainerType<*, *>): String = TODO() + +@JvmName("name") +fun > doGet(ep: ContainerType): String = TODO() + +fun main() {} diff --git a/compiler/testData/diagnostics/tests/inference/capturedTypes/dontCheckNewCapturedTypeSpecificChecksForOldOnes.txt b/compiler/testData/diagnostics/tests/inference/capturedTypes/dontCheckNewCapturedTypeSpecificChecksForOldOnes.txt new file mode 100644 index 00000000000..4b95baed272 --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/capturedTypes/dontCheckNewCapturedTypeSpecificChecksForOldOnes.txt @@ -0,0 +1,17 @@ +package + +public fun doGet(/*0*/ ep: ContainerType<*, *>): kotlin.String +@kotlin.jvm.JvmName(name = "name") public fun > doGet(/*0*/ ep: ContainerType): kotlin.String +public fun main(): kotlin.Unit + +public interface Container { + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} + +public interface ContainerType> { + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} 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 3b347177a8f..f4e171db409 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 @@ -12950,6 +12950,12 @@ public class DiagnosticTestGenerated extends AbstractDiagnosticTest { runTest("compiler/testData/diagnostics/tests/inference/capturedTypes/capturingFromArgumentOfFlexibleType.kt"); } + @Test + @TestMetadata("dontCheckNewCapturedTypeSpecificChecksForOldOnes.kt") + public void testDontCheckNewCapturedTypeSpecificChecksForOldOnes() throws Exception { + runTest("compiler/testData/diagnostics/tests/inference/capturedTypes/dontCheckNewCapturedTypeSpecificChecksForOldOnes.kt"); + } + @Test @TestMetadata("expectedTypeMismatchWithInVariance.kt") public void testExpectedTypeMismatchWithInVariance() throws Exception { diff --git a/core/compiler.common/src/org/jetbrains/kotlin/types/AbstractTypeChecker.kt b/core/compiler.common/src/org/jetbrains/kotlin/types/AbstractTypeChecker.kt index 7033b0c0c05..0b24b602cba 100644 --- a/core/compiler.common/src/org/jetbrains/kotlin/types/AbstractTypeChecker.kt +++ b/core/compiler.common/src/org/jetbrains/kotlin/types/AbstractTypeChecker.kt @@ -376,8 +376,9 @@ object AbstractTypeChecker { ): Boolean { val simpleSubArgumentType = subArgumentType.asSimpleType() - if (simpleSubArgumentType !is CapturedTypeMarker || !simpleSubArgumentType.typeConstructor().projection().isStarProjection()) - return false + if (simpleSubArgumentType !is CapturedTypeMarker || simpleSubArgumentType.isOldCapturedType() + || !simpleSubArgumentType.typeConstructor().projection().isStarProjection() + ) return false // Only 'for subtyping' captured types are approximated before adding constraints (see ConstraintInjector.addNewIncorporatedConstraint) // that can lead to adding problematic constraints like UPPER(Nothing) given by CapturedType(*) <: TypeVariable(A) if (simpleSubArgumentType.captureStatus() != CaptureStatus.FOR_SUBTYPING) return false diff --git a/core/compiler.common/src/org/jetbrains/kotlin/types/model/TypeSystemContext.kt b/core/compiler.common/src/org/jetbrains/kotlin/types/model/TypeSystemContext.kt index cdf44cbd56e..b2f87ed5c23 100644 --- a/core/compiler.common/src/org/jetbrains/kotlin/types/model/TypeSystemContext.kt +++ b/core/compiler.common/src/org/jetbrains/kotlin/types/model/TypeSystemContext.kt @@ -285,6 +285,7 @@ interface TypeSystemContext : TypeSystemOptimizationContext { fun SimpleTypeMarker.typeConstructor(): TypeConstructorMarker fun KotlinTypeMarker.withNullability(nullable: Boolean): KotlinTypeMarker + fun CapturedTypeMarker.isOldCapturedType(): Boolean fun CapturedTypeMarker.typeConstructor(): CapturedTypeConstructorMarker fun CapturedTypeMarker.captureStatus(): CaptureStatus fun CapturedTypeMarker.isProjectionNotNull(): Boolean diff --git a/core/descriptors/src/org/jetbrains/kotlin/types/checker/ClassicTypeSystemContext.kt b/core/descriptors/src/org/jetbrains/kotlin/types/checker/ClassicTypeSystemContext.kt index c99818f769b..80f46692f86 100644 --- a/core/descriptors/src/org/jetbrains/kotlin/types/checker/ClassicTypeSystemContext.kt +++ b/core/descriptors/src/org/jetbrains/kotlin/types/checker/ClassicTypeSystemContext.kt @@ -17,6 +17,7 @@ import org.jetbrains.kotlin.name.FqNameUnsafe import org.jetbrains.kotlin.name.Name import org.jetbrains.kotlin.resolve.DescriptorUtils import org.jetbrains.kotlin.resolve.calls.inference.CapturedType +import org.jetbrains.kotlin.resolve.calls.inference.CapturedTypeConstructor import org.jetbrains.kotlin.resolve.constants.IntegerLiteralTypeConstructor import org.jetbrains.kotlin.resolve.descriptorUtil.* import org.jetbrains.kotlin.resolve.isInlineClass @@ -462,6 +463,8 @@ interface ClassicTypeSystemContext : TypeSystemInferenceExtensionContext, TypeSy return this.captureStatus } + override fun CapturedTypeMarker.isOldCapturedType(): Boolean = this is CapturedType + override fun KotlinTypeMarker.isNullableType(): Boolean { require(this is KotlinType, this::errorMessage) return TypeUtils.isNullableType(this)