From 8b23d86bd92c35987db82c7e27e275ac7b8e3e70 Mon Sep 17 00:00:00 2001 From: Simon Ogorodnik Date: Mon, 13 Dec 2021 16:46:23 +0300 Subject: [PATCH] Treat mixed (subtyping, inference) sub-types properly in CST --- .../calls/NewCommonSuperTypeCalculator.kt | 18 +++++------------- 1 file changed, 5 insertions(+), 13 deletions(-) diff --git a/compiler/resolution.common/src/org/jetbrains/kotlin/resolve/calls/NewCommonSuperTypeCalculator.kt b/compiler/resolution.common/src/org/jetbrains/kotlin/resolve/calls/NewCommonSuperTypeCalculator.kt index e421b967b9a..ba5baa8eb53 100644 --- a/compiler/resolution.common/src/org/jetbrains/kotlin/resolve/calls/NewCommonSuperTypeCalculator.kt +++ b/compiler/resolution.common/src/org/jetbrains/kotlin/resolve/calls/NewCommonSuperTypeCalculator.kt @@ -204,28 +204,20 @@ object NewCommonSuperTypeCalculator { if (types.size == 1) return types.single() val nonTypeVariables = types.filter { !it.isStubTypeForVariableInSubtyping() && !isCapturedStubTypeForVariableInSubtyping(it) } - if (nonTypeVariables.size == 1) return nonTypeVariables.single() assert(nonTypeVariables.isNotEmpty()) { "There should be at least one non-stub type to compute common supertype but there are: $types" } - val (builderInferenceStubTypes, nonBuilderInferenceStubTypes) = types.partition { it.isStubTypeForBuilderInference() } - val areAllNonBuilderInferenceStubTypesNothing = - nonBuilderInferenceStubTypes.isNotEmpty() && nonBuilderInferenceStubTypes.all { it.isNothing() } + val (builderInferenceStubTypes, nonStubTypes) = nonTypeVariables.partition { it.isStubTypeForBuilderInference() } + val areAllNonStubTypesNothing = + nonStubTypes.isNotEmpty() && nonStubTypes.all { it.isNothing() } - if (nonBuilderInferenceStubTypes.size == 1 && !areAllNonBuilderInferenceStubTypesNothing) - return nonBuilderInferenceStubTypes.single() - - if (builderInferenceStubTypes.isNotEmpty()) { - // Common super type between any non stub type (except Nothing) and stub one is always Any? - if (nonBuilderInferenceStubTypes.isNotEmpty() && !areAllNonBuilderInferenceStubTypesNothing) { - return nullableAnyType() - } + if (builderInferenceStubTypes.isNotEmpty() && (nonStubTypes.isEmpty() || areAllNonStubTypesNothing)) { return commonSuperTypeForBuilderInferenceStubTypes(builderInferenceStubTypes, stateStubTypesNotEqual) } - val uniqueTypes = uniquify(nonTypeVariables, stateStubTypesNotEqual) + val uniqueTypes = uniquify(nonStubTypes, stateStubTypesNotEqual) if (uniqueTypes.size == 1) return uniqueTypes.single() val explicitSupertypes = filterSupertypes(uniqueTypes, stateStubTypesNotEqual)