[K/N] Make exception handling in initializers more consistent with jvm
^KT-57091
This commit is contained in:
committed by
Space Team
parent
0506d39d8a
commit
dc2e072af2
@@ -0,0 +1,31 @@
|
||||
// IGNORE_BACKEND: JS, JS_IR, JS_IR_ES6, WASM, NATIVE_WITH_LEGACY_MM
|
||||
// FILE: lib.kt
|
||||
val x: String = computeX()
|
||||
|
||||
fun computeX(): String = throw IllegalStateException("1")
|
||||
|
||||
// FILE: lib2.kt
|
||||
val y: String = computeY()
|
||||
|
||||
fun computeY(): String = throw Error("2")
|
||||
|
||||
|
||||
// FILE: main.kt
|
||||
fun box() : String {
|
||||
try {
|
||||
x
|
||||
return "FAIL 1"
|
||||
} catch(t: Error) {
|
||||
val cause = t.cause
|
||||
if (cause !is IllegalStateException) return "FAIL 2"
|
||||
if (cause.message != "1") return "FAIL 3"
|
||||
}
|
||||
try {
|
||||
y
|
||||
return "FAIL 4"
|
||||
} catch(t: Error) {
|
||||
if (t.cause != null) return "FAIL 5"
|
||||
if (t.message != "2") return "FAIL 6"
|
||||
}
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
// IGNORE_BACKEND: JS, JS_IR, JS_IR_ES6, WASM, NATIVE_WITH_LEGACY_MM
|
||||
// FILE: lib.kt
|
||||
val x: String = computeX()
|
||||
|
||||
fun computeX(): String = throw IllegalStateException("1")
|
||||
|
||||
val y: String = computeY()
|
||||
|
||||
fun computeY(): String = "2"
|
||||
|
||||
// FILE: main.kt
|
||||
fun box() : String {
|
||||
try {
|
||||
x
|
||||
return "FAIL 1"
|
||||
} catch(t: Error) {
|
||||
val cause = t.cause
|
||||
if (cause !is IllegalStateException) return "FAIL 2"
|
||||
if (cause.message != "1") return "FAIL 3"
|
||||
}
|
||||
try {
|
||||
y
|
||||
return "FAIL 4"
|
||||
} catch(t: Error) {
|
||||
if (t.cause != null) return "FAIL 5"
|
||||
}
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
// TARGET_BACKEND: NATIVE
|
||||
// IGNORE_BACKEND: NATIVE_WITH_LEGACY_MM
|
||||
// FILE: lib.kt
|
||||
import kotlin.native.concurrent.*
|
||||
|
||||
@ThreadLocal
|
||||
val x: String = computeX()
|
||||
|
||||
fun computeX(): String = error("1")
|
||||
|
||||
val y: String = computeY()
|
||||
|
||||
fun computeY(): String = "2"
|
||||
|
||||
// FILE: main.kt
|
||||
fun box() : String {
|
||||
try {
|
||||
x
|
||||
return "FAIL 1"
|
||||
} catch(t: Error) {
|
||||
val cause = t.cause
|
||||
if (cause !is IllegalStateException) return "FAIL 2"
|
||||
if (cause.message != "1") return "FAIL 3"
|
||||
}
|
||||
try {
|
||||
y
|
||||
return "FAIL 4"
|
||||
} catch(t: Error) {
|
||||
if (t.cause != null) return "FAIL 5"
|
||||
}
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
// TARGET_BACKEND: NATIVE
|
||||
// IGNORE_BACKEND: NATIVE_WITH_LEGACY_MM
|
||||
// FILE: lib.kt
|
||||
import kotlin.native.concurrent.*
|
||||
|
||||
@ThreadLocal
|
||||
val x: String = computeX()
|
||||
|
||||
fun computeX(): String = error("1")
|
||||
|
||||
@ThreadLocal
|
||||
val y: String = computeY()
|
||||
|
||||
fun computeY(): String = "2"
|
||||
|
||||
// FILE: main.kt
|
||||
fun box() : String {
|
||||
try {
|
||||
x
|
||||
return "FAIL 1"
|
||||
} catch(t: Error) {
|
||||
val cause = t.cause
|
||||
if (cause !is IllegalStateException) return "FAIL 2"
|
||||
if (cause.message != "1") return "FAIL 3"
|
||||
}
|
||||
try {
|
||||
y
|
||||
return "FAIL 4"
|
||||
} catch(t: Error) {
|
||||
if (t.cause != null) return "FAIL 5"
|
||||
}
|
||||
return "OK"
|
||||
}
|
||||
Reference in New Issue
Block a user