From fd6500c167c295d3791b5671e6c2d9a4fe0eceba Mon Sep 17 00:00:00 2001 From: Victor Petukhov Date: Mon, 31 Jan 2022 14:28:19 +0300 Subject: [PATCH] [FE 1.0] Set a fixation priority for self type variables less than any of ready for fixation kinds ^KT-51040 Fixed ^KT-49838 --- .../codegen/FirBlackBoxCodegenTestGenerated.java | 6 ++++++ .../components/VariableFixationFinder.kt | 4 ++-- .../testData/codegen/box/inference/kt51040.kt | 15 +++++++++++++++ compiler/testData/codegen/box/sealed/kt49752.kt | 3 --- .../codegen/BlackBoxCodegenTestGenerated.java | 6 ++++++ .../codegen/IrBlackBoxCodegenTestGenerated.java | 6 ++++++ .../codegen/LightAnalysisModeTestGenerated.java | 5 +++++ 7 files changed, 40 insertions(+), 5 deletions(-) create mode 100644 compiler/testData/codegen/box/inference/kt51040.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 79294dec68f..9a1ae4fb3d5 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 @@ -19039,6 +19039,12 @@ public class FirBlackBoxCodegenTestGenerated extends AbstractFirBlackBoxCodegenT runTest("compiler/testData/codegen/box/inference/kt49838.kt"); } + @Test + @TestMetadata("kt51040.kt") + public void testKt51040() throws Exception { + runTest("compiler/testData/codegen/box/inference/kt51040.kt"); + } + @Test @TestMetadata("lambdaWithStarReturn.kt") public void testLambdaWithStarReturn() throws Exception { diff --git a/compiler/resolution.common/src/org/jetbrains/kotlin/resolve/calls/inference/components/VariableFixationFinder.kt b/compiler/resolution.common/src/org/jetbrains/kotlin/resolve/calls/inference/components/VariableFixationFinder.kt index b9e30b9884f..051d174d81a 100644 --- a/compiler/resolution.common/src/org/jetbrains/kotlin/resolve/calls/inference/components/VariableFixationFinder.kt +++ b/compiler/resolution.common/src/org/jetbrains/kotlin/resolve/calls/inference/components/VariableFixationFinder.kt @@ -44,13 +44,13 @@ class VariableFixationFinder( enum class TypeVariableFixationReadiness { FORBIDDEN, WITHOUT_PROPER_ARGUMENT_CONSTRAINT, // proper constraint from arguments -- not from upper bound for type parameters + READY_FOR_FIXATION_DECLARED_UPPER_BOUND_WITH_SELF_TYPES, WITH_COMPLEX_DEPENDENCY, // if type variable T has constraint with non fixed type variable inside (non-top-level): T <: Foo WITH_TRIVIAL_OR_NON_PROPER_CONSTRAINTS, // proper trivial constraint from arguments, Nothing <: T RELATED_TO_ANY_OUTPUT_TYPE, FROM_INCORPORATION_OF_DECLARED_UPPER_BOUND, READY_FOR_FIXATION_UPPER, READY_FOR_FIXATION_LOWER, - READY_FOR_FIXATION_DECLARED_UPPER_BOUND_WITH_SELF_TYPES, READY_FOR_FIXATION, READY_FOR_FIXATION_REIFIED, } @@ -67,7 +67,7 @@ class VariableFixationFinder( ): TypeVariableFixationReadiness = when { !notFixedTypeVariables.contains(variable) || dependencyProvider.isVariableRelatedToTopLevelType(variable) -> TypeVariableFixationReadiness.FORBIDDEN - isTypeInferenceForSelfTypesSupported && hasOnlyDeclaredUpperBoundSelfTypes(variable) && !hasDependencyToOtherTypeVariables(variable) -> + isTypeInferenceForSelfTypesSupported && hasOnlyDeclaredUpperBoundSelfTypes(variable) -> TypeVariableFixationReadiness.READY_FOR_FIXATION_DECLARED_UPPER_BOUND_WITH_SELF_TYPES !variableHasProperArgumentConstraints(variable) -> TypeVariableFixationReadiness.WITHOUT_PROPER_ARGUMENT_CONSTRAINT hasDependencyToOtherTypeVariables(variable) -> TypeVariableFixationReadiness.WITH_COMPLEX_DEPENDENCY diff --git a/compiler/testData/codegen/box/inference/kt51040.kt b/compiler/testData/codegen/box/inference/kt51040.kt new file mode 100644 index 00000000000..ace828ee2d5 --- /dev/null +++ b/compiler/testData/codegen/box/inference/kt51040.kt @@ -0,0 +1,15 @@ +// WITH_STDLIB +// FULL_JDK +// TARGET_BACKEND: JVM + +import java.util.* + +inline fun > emptyEnumSet(): EnumSet = EnumSet.noneOf(T::class.java) +fun > enumSetOf(e: T): EnumSet = EnumSet.of(e) + +enum class SomeEnum { ONE } +val set = enumSetOf(SomeEnum.ONE).takeIf { it.size > 0 } ?: emptyEnumSet() + +fun box(): String { + return if (set.first() == SomeEnum.ONE) "OK" else "NOK" +} diff --git a/compiler/testData/codegen/box/sealed/kt49752.kt b/compiler/testData/codegen/box/sealed/kt49752.kt index 2574ccc7469..9103823998e 100644 --- a/compiler/testData/codegen/box/sealed/kt49752.kt +++ b/compiler/testData/codegen/box/sealed/kt49752.kt @@ -1,6 +1,3 @@ -// IGNORE_BACKEND_FIR: JVM_IR -// FIR status: several false UPPER_BOUND_VIOLATED are reported - abstract class Interpreter where IS : Interpreter.Intermediary, TS : Interpreter.Terminal, 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 0bdee914266..49e7447e891 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 @@ -18637,6 +18637,12 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest { runTest("compiler/testData/codegen/box/inference/kt49838.kt"); } + @Test + @TestMetadata("kt51040.kt") + public void testKt51040() throws Exception { + runTest("compiler/testData/codegen/box/inference/kt51040.kt"); + } + @Test @TestMetadata("lambdaWithStarReturn.kt") public void testLambdaWithStarReturn() 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 5b939950a17..e62d4cf37b1 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 @@ -19039,6 +19039,12 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes runTest("compiler/testData/codegen/box/inference/kt49838.kt"); } + @Test + @TestMetadata("kt51040.kt") + public void testKt51040() throws Exception { + runTest("compiler/testData/codegen/box/inference/kt51040.kt"); + } + @Test @TestMetadata("lambdaWithStarReturn.kt") public void testLambdaWithStarReturn() 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 7fa8a0f30dc..9c585dc6f4d 100644 --- a/compiler/tests-gen/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java +++ b/compiler/tests-gen/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java @@ -15487,6 +15487,11 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes runTest("compiler/testData/codegen/box/inference/kt47316.kt"); } + @TestMetadata("kt51040.kt") + public void testKt51040() throws Exception { + runTest("compiler/testData/codegen/box/inference/kt51040.kt"); + } + @TestMetadata("lambdaWithStarReturn.kt") public void testLambdaWithStarReturn() throws Exception { runTest("compiler/testData/codegen/box/inference/lambdaWithStarReturn.kt");