From 1c7ffb32763de3fd7b685421aeb935bd57e2ff5e Mon Sep 17 00:00:00 2001 From: Mikhail Glukhikh Date: Wed, 3 May 2023 11:09:32 +0200 Subject: [PATCH] ResultTypeResolver: don't allow Nothing as ILT subtype #KT-58379 Fixed --- .../components/ResultTypeResolver.kt | 5 ++-- .../tests/integerLiterals/sortedBy.fir.kt | 25 ------------------- .../tests/integerLiterals/sortedBy.kt | 1 + 3 files changed, 4 insertions(+), 27 deletions(-) delete mode 100644 compiler/testData/diagnostics/tests/integerLiterals/sortedBy.fir.kt diff --git a/compiler/resolution.common/src/org/jetbrains/kotlin/resolve/calls/inference/components/ResultTypeResolver.kt b/compiler/resolution.common/src/org/jetbrains/kotlin/resolve/calls/inference/components/ResultTypeResolver.kt index c35fbcb1a5d..97e7ef3644a 100644 --- a/compiler/resolution.common/src/org/jetbrains/kotlin/resolve/calls/inference/components/ResultTypeResolver.kt +++ b/compiler/resolution.common/src/org/jetbrains/kotlin/resolve/calls/inference/components/ResultTypeResolver.kt @@ -94,12 +94,13 @@ class ResultTypeResolver( // and the second one from UPPER/LOWER constraints (subType/superType based) // The logic of choice here is: // - if one type is null, we return another one - // - we return type from UPPER/LOWER constraints if it's more precise + // - we return type from UPPER/LOWER constraints if it's more precise (in fact, only Int/Short/Byte/Long is allowed here) // - otherwise we return ILT-based type return when { resultTypeFromEqualConstraint == null -> resultTypeFromDirection resultTypeFromDirection == null -> resultTypeFromEqualConstraint - AbstractTypeChecker.isSubtypeOf(c, resultTypeFromDirection, resultTypeFromEqualConstraint) -> resultTypeFromDirection + with(c) { !resultTypeFromDirection.typeConstructor().isNothingConstructor() } && + AbstractTypeChecker.isSubtypeOf(c, resultTypeFromDirection, resultTypeFromEqualConstraint) -> resultTypeFromDirection else -> resultTypeFromEqualConstraint } } diff --git a/compiler/testData/diagnostics/tests/integerLiterals/sortedBy.fir.kt b/compiler/testData/diagnostics/tests/integerLiterals/sortedBy.fir.kt deleted file mode 100644 index 2acb420d209..00000000000 --- a/compiler/testData/diagnostics/tests/integerLiterals/sortedBy.fir.kt +++ /dev/null @@ -1,25 +0,0 @@ -// WITH_STDLIB - -import Cause.* - -typealias ChallengeFunction = suspend (String) -> Unit - -enum class Cause { - FIRST, - SECOND, - ERROR, - LAST -} - -class Some { - internal val register = mutableListOf>() - - internal val challenges: List - get() = register.filter { it.first != ERROR }.sortedBy { - when (it.first) { - FIRST -> 1 - SECOND -> 2 - else -> throw AssertionError() - } - }.map { it.second } -} diff --git a/compiler/testData/diagnostics/tests/integerLiterals/sortedBy.kt b/compiler/testData/diagnostics/tests/integerLiterals/sortedBy.kt index ffe81162456..f99cfbfc135 100644 --- a/compiler/testData/diagnostics/tests/integerLiterals/sortedBy.kt +++ b/compiler/testData/diagnostics/tests/integerLiterals/sortedBy.kt @@ -1,3 +1,4 @@ +// FIR_IDENTICAL // WITH_STDLIB import Cause.*