CFA: additional jumps to catch / finally generated in the end of try / before exits from try #KT-5469 Fixed
Also #KT-13612 Fixed (cherry picked from commit 7c188b3)
This commit is contained in:
committed by
Mikhail Glukhikh
parent
43954699a7
commit
f8039249c6
+102
@@ -0,0 +1,102 @@
|
||||
// KT-13612 related tests (reassignment in try-catch-finally)
|
||||
|
||||
fun f1() {
|
||||
val n: Int
|
||||
try {
|
||||
<!UNUSED_VALUE!>n =<!> 1
|
||||
throw Exception()
|
||||
}
|
||||
catch (e: Exception) {
|
||||
// KT-13612: reassignment
|
||||
<!VAL_REASSIGNMENT!>n<!> = 2
|
||||
}
|
||||
n.hashCode()
|
||||
}
|
||||
|
||||
fun f2() {
|
||||
val <!ASSIGNED_BUT_NEVER_ACCESSED_VARIABLE!>n<!>: Int
|
||||
try {
|
||||
<!UNUSED_VALUE!>n =<!> 1
|
||||
throw Exception()
|
||||
}
|
||||
finally {
|
||||
<!UNUSED_VALUE!><!VAL_REASSIGNMENT!>n<!> =<!> 2
|
||||
}
|
||||
<!UNREACHABLE_CODE!>n.hashCode()<!>
|
||||
}
|
||||
|
||||
fun g1(flag: Boolean) {
|
||||
val n: Int
|
||||
try {
|
||||
if (flag) throw Exception()
|
||||
n = 1
|
||||
}
|
||||
catch (e: Exception) {
|
||||
// KT-13612: ? reassignment or definite assignment ?
|
||||
<!VAL_REASSIGNMENT!>n<!> = 2
|
||||
}
|
||||
n.hashCode()
|
||||
}
|
||||
|
||||
fun g2(flag: Boolean) {
|
||||
val n: Int
|
||||
try {
|
||||
if (flag) throw Exception()
|
||||
<!UNUSED_VALUE!>n =<!> 1
|
||||
}
|
||||
finally {
|
||||
<!VAL_REASSIGNMENT!>n<!> = 2
|
||||
}
|
||||
n.hashCode()
|
||||
}
|
||||
|
||||
fun h1(flag: Boolean) {
|
||||
val n = try {
|
||||
if (flag) throw Exception()
|
||||
1
|
||||
}
|
||||
catch (e: Exception) {
|
||||
2
|
||||
}
|
||||
n.hashCode()
|
||||
}
|
||||
|
||||
fun h2(flag: Boolean) {
|
||||
val n = try {
|
||||
if (flag) throw Exception()
|
||||
1
|
||||
}
|
||||
finally {
|
||||
<!UNUSED_EXPRESSION!>2<!>
|
||||
}
|
||||
n.hashCode()
|
||||
}
|
||||
|
||||
fun j(flag: Boolean) {
|
||||
if (flag) throw Exception()
|
||||
}
|
||||
|
||||
fun k1(flag: Boolean) {
|
||||
val n: Int
|
||||
try {
|
||||
n = 1
|
||||
j(flag)
|
||||
}
|
||||
catch (e: Exception) {
|
||||
// KT-13612: reassignment
|
||||
<!VAL_REASSIGNMENT!>n<!> = 2
|
||||
}
|
||||
n.hashCode()
|
||||
}
|
||||
|
||||
fun k2(flag: Boolean) {
|
||||
val n: Int
|
||||
try {
|
||||
<!UNUSED_VALUE!>n =<!> 1
|
||||
j(flag)
|
||||
}
|
||||
finally {
|
||||
<!VAL_REASSIGNMENT!>n<!> = 2
|
||||
}
|
||||
n.hashCode()
|
||||
}
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
package
|
||||
|
||||
public fun f1(): kotlin.Unit
|
||||
public fun f2(): kotlin.Unit
|
||||
public fun g1(/*0*/ flag: kotlin.Boolean): kotlin.Unit
|
||||
public fun g2(/*0*/ flag: kotlin.Boolean): kotlin.Unit
|
||||
public fun h1(/*0*/ flag: kotlin.Boolean): kotlin.Unit
|
||||
public fun h2(/*0*/ flag: kotlin.Boolean): kotlin.Unit
|
||||
public fun j(/*0*/ flag: kotlin.Boolean): kotlin.Unit
|
||||
public fun k1(/*0*/ flag: kotlin.Boolean): kotlin.Unit
|
||||
public fun k2(/*0*/ flag: kotlin.Boolean): kotlin.Unit
|
||||
+55
@@ -0,0 +1,55 @@
|
||||
fun exc(flag: Boolean) {
|
||||
if (flag) throw Exception()
|
||||
}
|
||||
|
||||
fun f1(flag: Boolean) {
|
||||
val n: Int
|
||||
try {
|
||||
if (flag) {
|
||||
<!UNUSED_VALUE!>n =<!> 1
|
||||
exc(flag)
|
||||
return
|
||||
}
|
||||
}
|
||||
catch (e: Exception) {
|
||||
// KT-13612: reassignment
|
||||
<!VAL_REASSIGNMENT!>n<!> = 3
|
||||
}
|
||||
<!UNINITIALIZED_VARIABLE!>n<!>.hashCode()
|
||||
}
|
||||
|
||||
fun f2(flag: Boolean) {
|
||||
while (true) {
|
||||
val n: Int
|
||||
try {
|
||||
if (flag) {
|
||||
<!UNUSED_VALUE!>n =<!> 1
|
||||
exc(flag)
|
||||
break
|
||||
}
|
||||
}
|
||||
catch (e: Exception) {
|
||||
// KT-13612: reassignment
|
||||
<!VAL_REASSIGNMENT!>n<!> = 3
|
||||
}
|
||||
<!UNINITIALIZED_VARIABLE!>n<!>.hashCode()
|
||||
}
|
||||
}
|
||||
|
||||
fun f3(flag: Boolean) {
|
||||
while (true) {
|
||||
val n: Int
|
||||
try {
|
||||
if (flag) {
|
||||
<!UNUSED_VALUE!>n =<!> 1
|
||||
exc(flag)
|
||||
continue
|
||||
}
|
||||
}
|
||||
catch (e: Exception) {
|
||||
// KT-13612: reassignment
|
||||
<!VAL_REASSIGNMENT!>n<!> = 3
|
||||
}
|
||||
<!UNINITIALIZED_VARIABLE!>n<!>.hashCode()
|
||||
}
|
||||
}
|
||||
Vendored
+6
@@ -0,0 +1,6 @@
|
||||
package
|
||||
|
||||
public fun exc(/*0*/ flag: kotlin.Boolean): kotlin.Unit
|
||||
public fun f1(/*0*/ flag: kotlin.Boolean): kotlin.Unit
|
||||
public fun f2(/*0*/ flag: kotlin.Boolean): kotlin.Unit
|
||||
public fun f3(/*0*/ flag: kotlin.Boolean): kotlin.Unit
|
||||
+36
@@ -0,0 +1,36 @@
|
||||
fun f() {
|
||||
var foo = 1
|
||||
try {
|
||||
foo = 2
|
||||
throw RuntimeException()
|
||||
} catch (e: Throwable) {
|
||||
foo.hashCode()
|
||||
}
|
||||
throw Exception()
|
||||
}
|
||||
|
||||
fun g() {
|
||||
var foo = 1
|
||||
try {
|
||||
foo = 2
|
||||
f()
|
||||
} catch (e: Throwable) {
|
||||
foo.hashCode()
|
||||
}
|
||||
}
|
||||
|
||||
fun h() {
|
||||
try {
|
||||
|
||||
}
|
||||
finally {
|
||||
var foo = 1
|
||||
try {
|
||||
foo = 2
|
||||
g()
|
||||
}
|
||||
catch (e: Throwable) {
|
||||
foo.hashCode()
|
||||
}
|
||||
}
|
||||
}
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
package
|
||||
|
||||
public fun f(): kotlin.Unit
|
||||
public fun g(): kotlin.Unit
|
||||
public fun h(): kotlin.Unit
|
||||
Reference in New Issue
Block a user