diff --git a/compiler/fir/modularized-tests/tests/org/jetbrains/kotlin/fir/AbstractModularizedTest.kt b/compiler/fir/modularized-tests/tests/org/jetbrains/kotlin/fir/AbstractModularizedTest.kt index 95eacbff39b..3c12f6d35c3 100644 --- a/compiler/fir/modularized-tests/tests/org/jetbrains/kotlin/fir/AbstractModularizedTest.kt +++ b/compiler/fir/modularized-tests/tests/org/jetbrains/kotlin/fir/AbstractModularizedTest.kt @@ -7,6 +7,7 @@ package org.jetbrains.kotlin.fir import org.jetbrains.kotlin.fir.scopes.ProcessorAction import org.jetbrains.kotlin.test.testFramework.KtUsefulTestCase +import org.jetbrains.kotlin.types.AbstractTypeChecker import org.w3c.dom.Node import org.w3c.dom.NodeList import java.io.File @@ -32,6 +33,16 @@ private fun NodeList.toList(): List { private val Node.childNodesList get() = childNodes.toList() abstract class AbstractModularizedTest : KtUsefulTestCase() { + override fun setUp() { + super.setUp() + AbstractTypeChecker.RUN_SLOW_ASSERTIONS = false + } + + override fun tearDown() { + super.tearDown() + AbstractTypeChecker.RUN_SLOW_ASSERTIONS = true + } + private fun loadModule(file: File): ModuleData { val factory = DocumentBuilderFactory.newInstance() @@ -92,4 +103,4 @@ abstract class AbstractModularizedTest : KtUsefulTestCase() { afterPass() } -} \ No newline at end of file +} diff --git a/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/inference/components/AbstractTypeCheckerContextForConstraintSystem.kt b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/inference/components/AbstractTypeCheckerContextForConstraintSystem.kt index 0b1d564258b..6159ddbf36b 100644 --- a/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/inference/components/AbstractTypeCheckerContextForConstraintSystem.kt +++ b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/inference/components/AbstractTypeCheckerContextForConstraintSystem.kt @@ -253,6 +253,7 @@ abstract class AbstractTypeCheckerContextForConstraintSystem : AbstractTypeCheck AbstractTypeChecker.isSubtypeOf(this as AbstractTypeCheckerContext, subType, superType) private fun assertInputTypes(subType: KotlinTypeMarker, superType: KotlinTypeMarker) { + if (!AbstractTypeChecker.RUN_SLOW_ASSERTIONS) return fun correctSubType(subType: SimpleTypeMarker) = subType.isSingleClassifierType() || subType.typeConstructor().isIntersection() || isMyTypeVariable(subType) || subType.isError() || subType.isIntegerLiteralType() @@ -278,4 +279,4 @@ abstract class AbstractTypeCheckerContextForConstraintSystem : AbstractTypeCheck is FlexibleTypeMarker -> f(lowerBound()) || f(upperBound()) else -> error("sealed") } -} \ No newline at end of file +} 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 2a378dc6314..6773eddf166 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 @@ -88,13 +88,15 @@ interface NewTypeSubstitutor: TypeSubstitutorMarker { "original lower type: '${capturedType.lowerType}" ) - typeConstructor.supertypes.forEach { supertype -> - substitute(supertype, keepAnnotation, runCapturedChecks = false)?.let { - throw IllegalStateException( - "Illegal type substitutor: $this, " + - "because for captured type '$type' supertype approximation should be null, but it is: '$supertype'," + - "original supertype: '$supertype'" - ) + if (AbstractTypeChecker.RUN_SLOW_ASSERTIONS) { + typeConstructor.supertypes.forEach { supertype -> + substitute(supertype, keepAnnotation, runCapturedChecks = false)?.let { + throw IllegalStateException( + "Illegal type substitutor: $this, " + + "because for captured type '$type' supertype approximation should be null, but it is: '$supertype'," + + "original supertype: '$supertype'" + ) + } } } @@ -178,4 +180,4 @@ class FreshVariableNewTypeSubstitutor(val freshVariables: List}", e.message) + return + } + + fail("Assertion error expected") + } } diff --git a/core/type-system/src/org/jetbrains/kotlin/types/AbstractTypeChecker.kt b/core/type-system/src/org/jetbrains/kotlin/types/AbstractTypeChecker.kt index fa8a711a2a3..cb31e57ea16 100644 --- a/core/type-system/src/org/jetbrains/kotlin/types/AbstractTypeChecker.kt +++ b/core/type-system/src/org/jetbrains/kotlin/types/AbstractTypeChecker.kt @@ -144,6 +144,8 @@ abstract class AbstractTypeCheckerContext : TypeSystemContext { } object AbstractTypeChecker { + @JvmField + var RUN_SLOW_ASSERTIONS = false fun isSubtypeOf(context: TypeCheckerProviderContext, subType: KotlinTypeMarker, superType: KotlinTypeMarker): Boolean { return AbstractTypeChecker.isSubtypeOf(context.newBaseTypeCheckerContext(true), subType, superType) @@ -223,11 +225,13 @@ object AbstractTypeChecker { } private fun AbstractTypeCheckerContext.isSubtypeOfForSingleClassifierType(subType: SimpleTypeMarker, superType: SimpleTypeMarker): Boolean { - assert(subType.isSingleClassifierType() || subType.typeConstructor().isIntersection() || subType.isAllowedTypeVariable) { - "Not singleClassifierType and not intersection subType: $subType" - } - assert(superType.isSingleClassifierType() || superType.isAllowedTypeVariable) { - "Not singleClassifierType superType: $superType" + if (AbstractTypeChecker.RUN_SLOW_ASSERTIONS) { + assert(subType.isSingleClassifierType() || subType.typeConstructor().isIntersection() || subType.isAllowedTypeVariable) { + "Not singleClassifierType and not intersection subType: $subType" + } + assert(superType.isSingleClassifierType() || superType.isAllowedTypeVariable) { + "Not singleClassifierType superType: $superType" + } } if (!AbstractNullabilityChecker.isPossibleSubtype(this, subType, superType)) return false @@ -469,12 +473,14 @@ object AbstractNullabilityChecker { } private fun AbstractTypeCheckerContext.runIsPossibleSubtype(subType: SimpleTypeMarker, superType: SimpleTypeMarker): Boolean { - // it makes for case String? & Any <: String - assert(subType.isSingleClassifierType() || subType.typeConstructor().isIntersection() || subType.isAllowedTypeVariable) { - "Not singleClassifierType and not intersection subType: $subType" - } - assert(superType.isSingleClassifierType() || superType.isAllowedTypeVariable) { - "Not singleClassifierType superType: $superType" + if (AbstractTypeChecker.RUN_SLOW_ASSERTIONS) { + // it makes for case String? & Any <: String + assert(subType.isSingleClassifierType() || subType.typeConstructor().isIntersection() || subType.isAllowedTypeVariable) { + "Not singleClassifierType and not intersection subType: $subType" + } + assert(superType.isSingleClassifierType() || superType.isAllowedTypeVariable) { + "Not singleClassifierType superType: $superType" + } } // superType is actually nullable @@ -525,4 +531,4 @@ object AbstractNullabilityChecker { }) { if (it.isMarkedNullable()) SupertypesPolicy.None else SupertypesPolicy.LowerIfFlexible } -} \ No newline at end of file +}