Quick-fix for reassignment in try / catch (fold to assignment) #KT-13778 Fixed
This commit is contained in:
@@ -0,0 +1,16 @@
|
||||
// "Lift assignment out of 'try' expression" "false"
|
||||
// ACTION: Make variable mutable
|
||||
// ERROR: Val cannot be reassigned
|
||||
// WITH_RUNTIME
|
||||
|
||||
fun foo(arg: Boolean) {
|
||||
val x: Int
|
||||
try {
|
||||
if (arg) {
|
||||
x = 1
|
||||
}
|
||||
}
|
||||
catch (e: Exception) {
|
||||
<caret>x = 2
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
// "Lift assignment out of 'try' expression" "true"
|
||||
// WITH_RUNTIME
|
||||
|
||||
fun foo() {
|
||||
val x: Int
|
||||
try {
|
||||
x = 1
|
||||
}
|
||||
catch (e: Exception) {
|
||||
<caret>x = 2
|
||||
}
|
||||
finally {}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
// "Lift assignment out of 'try' expression" "true"
|
||||
// WITH_RUNTIME
|
||||
|
||||
fun foo() {
|
||||
val x: Int
|
||||
x = try {
|
||||
1
|
||||
} catch (e: Exception) {
|
||||
2
|
||||
} finally {}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
// "Lift assignment out of 'try' expression" "true"
|
||||
// WITH_RUNTIME
|
||||
|
||||
fun foo() {
|
||||
val x: Int
|
||||
try {
|
||||
x = 1
|
||||
}
|
||||
catch (e: RuntimeException) {
|
||||
<caret>x = 2
|
||||
}
|
||||
catch (e: Exception) {
|
||||
x = 3
|
||||
}
|
||||
catch (e: Throwable) {
|
||||
x = 4
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
// "Lift assignment out of 'try' expression" "true"
|
||||
// WITH_RUNTIME
|
||||
|
||||
fun foo() {
|
||||
val x: Int
|
||||
x = try {
|
||||
1
|
||||
} catch (e: RuntimeException) {
|
||||
2
|
||||
} catch (e: Exception) {
|
||||
3
|
||||
} catch (e: Throwable) {
|
||||
4
|
||||
}
|
||||
}
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
// "Lift assignment out of 'try' expression" "false"
|
||||
// ACTION: Make variable mutable
|
||||
// ERROR: Val cannot be reassigned
|
||||
// ERROR: Val cannot be reassigned
|
||||
// WITH_RUNTIME
|
||||
|
||||
fun foo() {
|
||||
val x = 1
|
||||
try {
|
||||
val x = 2
|
||||
x = 3
|
||||
}
|
||||
catch(e: Exception) {
|
||||
<caret>x = 4
|
||||
}
|
||||
}
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
// "Lift assignment out of 'try' expression" "true"
|
||||
// WITH_RUNTIME
|
||||
|
||||
fun foo() {
|
||||
val x: Int
|
||||
try {
|
||||
x = 1
|
||||
}
|
||||
catch (e: Exception) {
|
||||
<caret>x = 2
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
// "Lift assignment out of 'try' expression" "true"
|
||||
// WITH_RUNTIME
|
||||
|
||||
fun foo() {
|
||||
val x: Int
|
||||
x = try {
|
||||
1
|
||||
} catch (e: Exception) {
|
||||
2
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user