From 36606fd9441e455187e52f50506f543dfdb60022 Mon Sep 17 00:00:00 2001 From: Denis Zharkov Date: Fri, 12 Feb 2016 16:30:14 +0300 Subject: [PATCH] Run slow flexible type assertions only in test mode --- .../FlexibleTypeAssertionsEnabledTest.kt | 38 +++++++++++++++++++ .../KotlinTestWithEnvironmentManagement.java | 2 + .../jetbrains/kotlin/types/flexibleTypes.kt | 5 ++- 3 files changed, 43 insertions(+), 2 deletions(-) create mode 100644 compiler/tests/org/jetbrains/kotlin/jvm/compiler/FlexibleTypeAssertionsEnabledTest.kt diff --git a/compiler/tests/org/jetbrains/kotlin/jvm/compiler/FlexibleTypeAssertionsEnabledTest.kt b/compiler/tests/org/jetbrains/kotlin/jvm/compiler/FlexibleTypeAssertionsEnabledTest.kt new file mode 100644 index 00000000000..410c7c2ec2f --- /dev/null +++ b/compiler/tests/org/jetbrains/kotlin/jvm/compiler/FlexibleTypeAssertionsEnabledTest.kt @@ -0,0 +1,38 @@ +/* + * Copyright 2010-2016 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.jetbrains.kotlin.jvm.compiler + +import org.jetbrains.kotlin.load.java.lazy.types.LazyJavaTypeResolver +import org.jetbrains.kotlin.resolve.jvm.platform.JvmPlatform +import org.jetbrains.kotlin.test.KotlinTestWithEnvironmentManagement + +class FlexibleTypeAssertionsEnabledTest : KotlinTestWithEnvironmentManagement() { + + fun testAssertionsAreOn() { + val builtIns = JvmPlatform.builtIns + + try { + LazyJavaTypeResolver.FlexibleJavaClassifierTypeCapabilities.create( + builtIns.intType, builtIns.stringType).arguments + } catch (e: AssertionError) { + assertEquals("Lower bound Int of a flexible type must be a subtype of the upper bound String", e.message) + return + } + + fail("Assertion error expected") + } +} diff --git a/compiler/tests/org/jetbrains/kotlin/test/KotlinTestWithEnvironmentManagement.java b/compiler/tests/org/jetbrains/kotlin/test/KotlinTestWithEnvironmentManagement.java index 8acec9aa4d6..2888dc6334e 100644 --- a/compiler/tests/org/jetbrains/kotlin/test/KotlinTestWithEnvironmentManagement.java +++ b/compiler/tests/org/jetbrains/kotlin/test/KotlinTestWithEnvironmentManagement.java @@ -19,10 +19,12 @@ package org.jetbrains.kotlin.test; import com.intellij.testFramework.UsefulTestCase; import org.jetbrains.annotations.NotNull; import org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment; +import org.jetbrains.kotlin.types.DelegatingFlexibleType; public abstract class KotlinTestWithEnvironmentManagement extends UsefulTestCase { static { System.setProperty("java.awt.headless", "true"); + DelegatingFlexibleType.RUN_SLOW_ASSERTIONS = true; } @NotNull diff --git a/core/descriptors/src/org/jetbrains/kotlin/types/flexibleTypes.kt b/core/descriptors/src/org/jetbrains/kotlin/types/flexibleTypes.kt index 09b333c9901..68f03987fea 100644 --- a/core/descriptors/src/org/jetbrains/kotlin/types/flexibleTypes.kt +++ b/core/descriptors/src/org/jetbrains/kotlin/types/flexibleTypes.kt @@ -128,7 +128,8 @@ open class DelegatingFlexibleType protected constructor( return DelegatingFlexibleType(lowerBound, upperBound, extraCapabilities) } - internal val ASSERTIONS_ENABLED = DelegatingFlexibleType::class.java.desiredAssertionStatus() + @JvmField + var RUN_SLOW_ASSERTIONS = false } // These assertions are needed for checking invariants of flexible types. @@ -140,7 +141,7 @@ open class DelegatingFlexibleType protected constructor( private var assertionsDone = false private fun runAssertions() { - if (assertionsDone || !ASSERTIONS_ENABLED) return + if (!RUN_SLOW_ASSERTIONS || assertionsDone) return assertionsDone = true assert (!lowerBound.isFlexible()) { "Lower bound of a flexible type can not be flexible: $lowerBound" }