JVM_IR: Add more local variable tests for finally code.
This commit is contained in:
committed by
Mikhael Bogdanov
parent
6095d8a7fa
commit
0c77565104
+2
-2
@@ -423,7 +423,7 @@ class ExpressionCodegen(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun addLocalVariableGapsForFinallyBlocks(
|
private fun splitLocalVariableRangesByFinallyBlocks(
|
||||||
info: BlockInfo,
|
info: BlockInfo,
|
||||||
tryWithFinallyInfo: TryWithFinallyInfo,
|
tryWithFinallyInfo: TryWithFinallyInfo,
|
||||||
gapStart: Label,
|
gapStart: Label,
|
||||||
@@ -1276,7 +1276,7 @@ class ExpressionCodegen(
|
|||||||
// Split the local variables for the blocks on the way to the finally. Variables introduced in these blocks do not
|
// Split the local variables for the blocks on the way to the finally. Variables introduced in these blocks do not
|
||||||
// cover the finally block code.
|
// cover the finally block code.
|
||||||
val endOfFinallyCode = markNewLinkedLabel()
|
val endOfFinallyCode = markNewLinkedLabel()
|
||||||
addLocalVariableGapsForFinallyBlocks(data, tryWithFinallyInfo, gapStart, endOfFinallyCode)
|
splitLocalVariableRangesByFinallyBlocks(data, tryWithFinallyInfo, gapStart, endOfFinallyCode)
|
||||||
|
|
||||||
val gapEnd = afterJumpLabel ?: endOfFinallyCode
|
val gapEnd = afterJumpLabel ?: endOfFinallyCode
|
||||||
tryWithFinallyInfo.gaps.add(gapStart to gapEnd)
|
tryWithFinallyInfo.gaps.add(gapStart to gapEnd)
|
||||||
|
|||||||
@@ -0,0 +1,37 @@
|
|||||||
|
// FILE: test.kt
|
||||||
|
|
||||||
|
fun box(): String {
|
||||||
|
try {
|
||||||
|
for (i in 0 until 1) {
|
||||||
|
try {
|
||||||
|
val x = "x"
|
||||||
|
throw RuntimeException(x)
|
||||||
|
} catch (e: Exception) {
|
||||||
|
val y = "y"
|
||||||
|
val z = "z"
|
||||||
|
break // TODO: why does the break not have a line number so we can stop on it?
|
||||||
|
} finally {
|
||||||
|
throw RuntimeException("$i") // TODO: `e` should not be visible here
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} finally {
|
||||||
|
return "OK"
|
||||||
|
} // TODO: why do we go to this line before going to the line above for the finally block.
|
||||||
|
return "FAIL"
|
||||||
|
}
|
||||||
|
|
||||||
|
// The local variables `z` and `y` are visible in the finally block with old backend.
|
||||||
|
// IGNORE_BACKEND: JVM
|
||||||
|
|
||||||
|
// LOCAL VARIABLES
|
||||||
|
// test.kt:4 box:
|
||||||
|
// test.kt:5 box:
|
||||||
|
// test.kt:6 box: i:int=0:int
|
||||||
|
// test.kt:7 box: i:int=0:int
|
||||||
|
// test.kt:8 box: i:int=0:int, x:java.lang.String="x":java.lang.String
|
||||||
|
// test.kt:9 box: i:int=0:int
|
||||||
|
// test.kt:10 box: i:int=0:int, e:java.lang.Exception=java.lang.RuntimeException
|
||||||
|
// test.kt:11 box: i:int=0:int, e:java.lang.Exception=java.lang.RuntimeException, y:java.lang.String="y":java.lang.String
|
||||||
|
// test.kt:14 box: i:int=0:int, e:java.lang.Exception=java.lang.RuntimeException
|
||||||
|
// test.kt:19 box:
|
||||||
|
// test.kt:18 box:
|
||||||
@@ -0,0 +1,38 @@
|
|||||||
|
// FILE: test.kt
|
||||||
|
|
||||||
|
fun box(): String {
|
||||||
|
try {
|
||||||
|
for (i in 0 until 1) {
|
||||||
|
try {
|
||||||
|
val x = "x"
|
||||||
|
throw RuntimeException(x)
|
||||||
|
} catch (e: Exception) {
|
||||||
|
val y = "y"
|
||||||
|
val z = "z"
|
||||||
|
continue // TODO: why does the continue not have a line number so we stop here?
|
||||||
|
} finally {
|
||||||
|
throw RuntimeException("$i") // TODO: `e` should not be visible here
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} finally {
|
||||||
|
return "OK"
|
||||||
|
} // TODO: why stop here before the line above for the finally block?
|
||||||
|
return "FAIL"
|
||||||
|
}
|
||||||
|
|
||||||
|
// The local variables `z` and `y` are visible in the finally block with old backend.
|
||||||
|
// IGNORE_BACKEND: JVM
|
||||||
|
|
||||||
|
// LOCAL VARIABLES
|
||||||
|
// test.kt:4 box:
|
||||||
|
// test.kt:5 box:
|
||||||
|
// test.kt:6 box: i:int=0:int
|
||||||
|
// test.kt:7 box: i:int=0:int
|
||||||
|
// test.kt:8 box: i:int=0:int, x:java.lang.String="x":java.lang.String
|
||||||
|
// test.kt:9 box: i:int=0:int
|
||||||
|
// test.kt:10 box: i:int=0:int, e:java.lang.Exception=java.lang.RuntimeException
|
||||||
|
// test.kt:11 box: i:int=0:int, e:java.lang.Exception=java.lang.RuntimeException, y:java.lang.String="y":java.lang.String
|
||||||
|
// test.kt:14 box: i:int=0:int, e:java.lang.Exception=java.lang.RuntimeException
|
||||||
|
// test.kt:19 box:
|
||||||
|
// test.kt:18 box:
|
||||||
|
|
||||||
@@ -0,0 +1,36 @@
|
|||||||
|
// FILE: test.kt
|
||||||
|
|
||||||
|
fun box(): String {
|
||||||
|
try {
|
||||||
|
for (i in 0 until 1) {
|
||||||
|
try {
|
||||||
|
val x = "x"
|
||||||
|
throw RuntimeException(x)
|
||||||
|
} catch (e: Exception) {
|
||||||
|
val y = "y"
|
||||||
|
return "FAIL1"
|
||||||
|
} finally {
|
||||||
|
return "FAIL2" // TODO: `e` should not be visible here.
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} finally {
|
||||||
|
return "OK" // TODO: `e` should not be visible here.
|
||||||
|
}
|
||||||
|
return "FAIL3"
|
||||||
|
}
|
||||||
|
|
||||||
|
// The local variables `y` and `i` are visible in finally blocks with old backend.
|
||||||
|
// IGNORE_BACKEND: JVM
|
||||||
|
|
||||||
|
// LOCAL VARIABLES
|
||||||
|
// test.kt:4 box:
|
||||||
|
// test.kt:5 box:
|
||||||
|
// test.kt:6 box: i:int=0:int
|
||||||
|
// test.kt:7 box: i:int=0:int
|
||||||
|
// test.kt:8 box: i:int=0:int, x:java.lang.String="x":java.lang.String
|
||||||
|
// test.kt:9 box: i:int=0:int
|
||||||
|
// test.kt:10 box: i:int=0:int, e:java.lang.Exception=java.lang.RuntimeException
|
||||||
|
// test.kt:11 box: i:int=0:int, e:java.lang.Exception=java.lang.RuntimeException, y:java.lang.String="y":java.lang.String
|
||||||
|
// test.kt:13 box: i:int=0:int, e:java.lang.Exception=java.lang.RuntimeException
|
||||||
|
// test.kt:17 box: e:java.lang.Exception=java.lang.RuntimeException
|
||||||
|
|
||||||
@@ -0,0 +1,26 @@
|
|||||||
|
// FILE: test.kt
|
||||||
|
|
||||||
|
fun box(): String {
|
||||||
|
try {
|
||||||
|
for (i in 0 until 1) {
|
||||||
|
try {
|
||||||
|
val x = "x"
|
||||||
|
var y = "y"
|
||||||
|
} finally {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} finally {
|
||||||
|
return "OK"
|
||||||
|
}
|
||||||
|
return "FAIL"
|
||||||
|
}
|
||||||
|
|
||||||
|
// LOCAL VARIABLES
|
||||||
|
// test.kt:4 box:
|
||||||
|
// test.kt:5 box:
|
||||||
|
// test.kt:6 box: i:int=0:int
|
||||||
|
// test.kt:7 box: i:int=0:int
|
||||||
|
// test.kt:8 box: i:int=0:int, x:java.lang.String="x":java.lang.String
|
||||||
|
// test.kt:10 box: i:int=0:int
|
||||||
|
// test.kt:14 box:
|
||||||
@@ -0,0 +1,27 @@
|
|||||||
|
// FILE: test.kt
|
||||||
|
|
||||||
|
fun box(): String {
|
||||||
|
try {
|
||||||
|
for (i in 0 until 1) {
|
||||||
|
try {
|
||||||
|
val x = "x"
|
||||||
|
val y = "y"
|
||||||
|
} finally {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} finally {
|
||||||
|
return "OK"
|
||||||
|
}
|
||||||
|
return "FAIL"
|
||||||
|
}
|
||||||
|
|
||||||
|
// LOCAL VARIABLES
|
||||||
|
// test.kt:4 box:
|
||||||
|
// test.kt:5 box:
|
||||||
|
// test.kt:6 box: i:int=0:int
|
||||||
|
// test.kt:7 box: i:int=0:int
|
||||||
|
// test.kt:8 box: i:int=0:int, x:java.lang.String="x":java.lang.String
|
||||||
|
// test.kt:10 box: i:int=0:int
|
||||||
|
// test.kt:5 box: i:int=0:int
|
||||||
|
// test.kt:14 box:
|
||||||
@@ -0,0 +1,29 @@
|
|||||||
|
// FILE: test.kt
|
||||||
|
|
||||||
|
fun box(): String {
|
||||||
|
try {
|
||||||
|
for (i in 0 until 1) {
|
||||||
|
try {
|
||||||
|
val x = "x"
|
||||||
|
val y = "y"
|
||||||
|
} finally {
|
||||||
|
return "FAIL1"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} finally {
|
||||||
|
return "OK"
|
||||||
|
}
|
||||||
|
return "FAIL2"
|
||||||
|
}
|
||||||
|
|
||||||
|
// The local `i` is visible in the finally block with old backend.
|
||||||
|
// IGNORE_BACKEND: JVM
|
||||||
|
|
||||||
|
// LOCAL VARIABLES
|
||||||
|
// test.kt:4 box:
|
||||||
|
// test.kt:5 box:
|
||||||
|
// test.kt:6 box: i:int=0:int
|
||||||
|
// test.kt:7 box: i:int=0:int
|
||||||
|
// test.kt:8 box: i:int=0:int, x:java.lang.String="x":java.lang.String
|
||||||
|
// test.kt:10 box: i:int=0:int
|
||||||
|
// test.kt:14 box:
|
||||||
+1
-1
@@ -20,7 +20,7 @@ fun compute(): String {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
} finally {
|
} finally {
|
||||||
x = "OK"
|
x = "OK" // TODO: `e` should not be visible here.
|
||||||
}
|
}
|
||||||
return "FAIL"
|
return "FAIL"
|
||||||
}
|
}
|
||||||
|
|||||||
Generated
+36
@@ -98,6 +98,42 @@ public class IrLocalVariableTestGenerated extends AbstractIrLocalVariableTest {
|
|||||||
runTest("compiler/testData/debug/localVariables/tryFinally10.kt");
|
runTest("compiler/testData/debug/localVariables/tryFinally10.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("tryFinally11.kt")
|
||||||
|
public void testTryFinally11() throws Exception {
|
||||||
|
runTest("compiler/testData/debug/localVariables/tryFinally11.kt");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("tryFinally12.kt")
|
||||||
|
public void testTryFinally12() throws Exception {
|
||||||
|
runTest("compiler/testData/debug/localVariables/tryFinally12.kt");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("tryFinally13.kt")
|
||||||
|
public void testTryFinally13() throws Exception {
|
||||||
|
runTest("compiler/testData/debug/localVariables/tryFinally13.kt");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("tryFinally14.kt")
|
||||||
|
public void testTryFinally14() throws Exception {
|
||||||
|
runTest("compiler/testData/debug/localVariables/tryFinally14.kt");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("tryFinally15.kt")
|
||||||
|
public void testTryFinally15() throws Exception {
|
||||||
|
runTest("compiler/testData/debug/localVariables/tryFinally15.kt");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("tryFinally16.kt")
|
||||||
|
public void testTryFinally16() throws Exception {
|
||||||
|
runTest("compiler/testData/debug/localVariables/tryFinally16.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@TestMetadata("tryFinally2.kt")
|
@TestMetadata("tryFinally2.kt")
|
||||||
public void testTryFinally2() throws Exception {
|
public void testTryFinally2() throws Exception {
|
||||||
|
|||||||
Generated
+36
@@ -98,6 +98,42 @@ public class LocalVariableTestGenerated extends AbstractLocalVariableTest {
|
|||||||
runTest("compiler/testData/debug/localVariables/tryFinally10.kt");
|
runTest("compiler/testData/debug/localVariables/tryFinally10.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("tryFinally11.kt")
|
||||||
|
public void testTryFinally11() throws Exception {
|
||||||
|
runTest("compiler/testData/debug/localVariables/tryFinally11.kt");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("tryFinally12.kt")
|
||||||
|
public void testTryFinally12() throws Exception {
|
||||||
|
runTest("compiler/testData/debug/localVariables/tryFinally12.kt");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("tryFinally13.kt")
|
||||||
|
public void testTryFinally13() throws Exception {
|
||||||
|
runTest("compiler/testData/debug/localVariables/tryFinally13.kt");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("tryFinally14.kt")
|
||||||
|
public void testTryFinally14() throws Exception {
|
||||||
|
runTest("compiler/testData/debug/localVariables/tryFinally14.kt");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("tryFinally15.kt")
|
||||||
|
public void testTryFinally15() throws Exception {
|
||||||
|
runTest("compiler/testData/debug/localVariables/tryFinally15.kt");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("tryFinally16.kt")
|
||||||
|
public void testTryFinally16() throws Exception {
|
||||||
|
runTest("compiler/testData/debug/localVariables/tryFinally16.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@TestMetadata("tryFinally2.kt")
|
@TestMetadata("tryFinally2.kt")
|
||||||
public void testTryFinally2() throws Exception {
|
public void testTryFinally2() throws Exception {
|
||||||
|
|||||||
Reference in New Issue
Block a user