JVM, JVM IR: Fix assertion status for regenerated anonymous objects

We always set the $assertionsDisabled field based on the top-level
enclosing class. This means that for anonymous objects we have to
rewrite the call to Class.desiredAssertionStatus.
This commit is contained in:
Steven Schäfer
2020-02-14 11:09:32 +01:00
committed by Ilmir Usmanov
parent 272f6abe69
commit ba90e87756
5 changed files with 53 additions and 19 deletions
@@ -1,6 +1,4 @@
// TARGET_BACKEND: JVM
// IGNORE_BACKEND: JVM_IR
// IGNORE_BACKEND_MULTI_MODULE: JVM_IR
// FILE: inline.kt
// KOTLIN_CONFIGURATION_FLAGS: ASSERTIONS_MODE=jvm
// WITH_RUNTIME
@@ -185,8 +183,9 @@ class ShouldBeEnabled : Checker {
fun setDesiredAssertionStatus(v: Boolean): Checker {
val loader = Checker::class.java.classLoader
loader.setDefaultAssertionStatus(false)
loader.setPackageAssertionStatus("test", v)
val c = loader.loadClass(if (v) "ShouldBeEnabled" else "ShouldBeDisabled")
val className = if (v) "ShouldBeEnabled" else "ShouldBeDisabled"
loader.setClassAssertionStatus(className, v)
val c = loader.loadClass(className)
return c.newInstance() as Checker
}
@@ -202,14 +201,32 @@ fun box(): String {
if (c.checkFalseWithMessageFalse()) return "FAIL 31"
c = setDesiredAssertionStatus(true)
if (c.checkTrueTrue()) return "FAIL 100"
if (c.checkTrueFalse()) return "FAIL 101"
if (c.checkTrueWithMessageTrue()) return "FAIL 110"
if (c.checkTrueWithMessageFalse()) return "FAIL 111"
if (c.checkFalseTrue()) return "FAIL 120"
if (c.checkFalseFalse()) return "FAIL 121"
if (c.checkFalseWithMessageTrue()) return "FAIL 130"
if (c.checkFalseWithMessageFalse()) return "FAIL 131"
if (!c.checkTrueTrue()) return "FAIL 100"
try {
c.checkTrueFalse()
return "FAIL 101"
} catch (ignore: AssertionError) {}
if (!c.checkTrueWithMessageTrue()) return "FAIL 110"
try {
c.checkTrueWithMessageFalse()
return "FAIL 111"
} catch (ignore: AssertionError) {}
try {
c.checkFalseTrue()
return "FAIL 120"
} catch (ignore: AssertionError) {}
try {
c.checkFalseFalse()
return "FAIL 121"
} catch (ignore: AssertionError) {}
try {
c.checkFalseWithMessageTrue()
return "FAIL 130"
} catch (ignore: AssertionError) {}
try {
c.checkFalseWithMessageFalse()
return "FAIL 131"
} catch (ignore: AssertionError) {}
return "OK"
}
@@ -1,6 +1,3 @@
// This test is ignored until KT-36794 is fixed
// IGNORE_BACKEND: JVM
// IGNORE_BACKEND: JVM_IR
// KOTLIN_CONFIGURATION_FLAGS: ASSERTIONS_MODE=jvm
inline fun inlineMe(crossinline c : () -> Unit) = {