Run slow flexible type assertions only in test mode
This commit is contained in:
@@ -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")
|
||||
}
|
||||
}
|
||||
@@ -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
|
||||
|
||||
@@ -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" }
|
||||
|
||||
Reference in New Issue
Block a user