mirror of
https://github.com/jlengrand/kotlin.git
synced 2026-05-10 08:31:29 +00:00
NOTE: jvmCrossinlineLambdaDeclarationSite.kt is muted because the inliner does not remap references to an anonymous object's parent class after regenerating it. Unlike the JVM backend, JVM_IR uses the top level named class' assertion status for all inner classes. (The test used to pass because the lambda in `inline fun call` read the `$assertionsDisabled` field of `CrossinlineLambdaContainer`, which was not reloaded after changing the assertion status of package `test`.)
73 lines
1.6 KiB
Kotlin
Vendored
73 lines
1.6 KiB
Kotlin
Vendored
// TARGET_BACKEND: JVM
|
|
// FILE: inline.kt
|
|
// KOTLIN_CONFIGURATION_FLAGS: ASSERTIONS_MODE=jvm
|
|
// WITH_RUNTIME
|
|
// NO_CHECK_LAMBDA_INLINING
|
|
|
|
package test
|
|
|
|
object CrossinlineLambdaContainer {
|
|
inline fun call(crossinline c: () -> Boolean) {
|
|
Runnable { assert(c()) }.run()
|
|
}
|
|
}
|
|
|
|
// FILE: inlineSite.kt
|
|
// KOTLIN_CONFIGURATION_FLAGS: ASSERTIONS_MODE=jvm
|
|
|
|
import test.CrossinlineLambdaContainer.call
|
|
|
|
interface Checker {
|
|
fun checkTrue(): Boolean
|
|
fun checkFalse(): Boolean
|
|
}
|
|
|
|
class ShouldBeDisabled : Checker {
|
|
override fun checkTrue(): Boolean {
|
|
var hit = false
|
|
call { hit = true; true }
|
|
return hit
|
|
}
|
|
|
|
override fun checkFalse(): Boolean {
|
|
var hit = false
|
|
call { hit = true; false }
|
|
return hit
|
|
}
|
|
}
|
|
|
|
class ShouldBeEnabled : Checker {
|
|
override fun checkTrue(): Boolean {
|
|
var hit = false
|
|
call { hit = true; true }
|
|
return hit
|
|
}
|
|
|
|
override fun checkFalse(): Boolean {
|
|
var hit = false
|
|
call { hit = true; false }
|
|
return hit
|
|
}
|
|
}
|
|
|
|
fun setDesiredAssertionStatus(v: Boolean): Checker {
|
|
val loader = Checker::class.java.classLoader
|
|
loader.setDefaultAssertionStatus(v)
|
|
val c = loader.loadClass(if (v) "ShouldBeEnabled" else "ShouldBeDisabled")
|
|
return c.newInstance() as Checker
|
|
}
|
|
|
|
fun box(): String {
|
|
var c = setDesiredAssertionStatus(false)
|
|
if (c.checkTrue()) return "FAIL 0"
|
|
if (c.checkFalse()) return "FAIL 2"
|
|
c = setDesiredAssertionStatus(true)
|
|
if (!c.checkTrue()) return "FAIL 4"
|
|
try {
|
|
c.checkFalse()
|
|
return "FAIL 6"
|
|
} catch (ignore: AssertionError) {
|
|
}
|
|
return "OK"
|
|
}
|