FIR checker: report val reassignment
This commit is contained in:
committed by
Dmitriy Novozhilov
parent
b128577508
commit
f1fa290d49
Vendored
+4
-4
@@ -63,7 +63,7 @@ fun t4(a: A) {
|
||||
|
||||
fun t1() {
|
||||
val a : Int = 1
|
||||
a = 2
|
||||
<!VAL_REASSIGNMENT!>a<!> = 2
|
||||
|
||||
var b : Int = 1
|
||||
b = 3
|
||||
@@ -83,8 +83,8 @@ enum class ProtocolState {
|
||||
|
||||
fun t3() {
|
||||
val x: ProtocolState = ProtocolState.WAITING
|
||||
x = x.signal()
|
||||
x = x.signal() //repeat for x
|
||||
<!VAL_REASSIGNMENT!>x<!> = x.signal()
|
||||
<!VAL_REASSIGNMENT!>x<!> = x.signal() //repeat for x
|
||||
}
|
||||
|
||||
fun t4() {
|
||||
@@ -326,7 +326,7 @@ fun func() {
|
||||
val a = object {
|
||||
val x = b
|
||||
init {
|
||||
b = 4
|
||||
<!VAL_REASSIGNMENT!>b<!> = 4
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+6
-6
@@ -24,7 +24,7 @@ fun assignedInTryAndCatch() {
|
||||
try {
|
||||
a = 42
|
||||
} catch (e: Exception) {
|
||||
a = 41
|
||||
<!VAL_REASSIGNMENT!>a<!> = 41
|
||||
} finally {
|
||||
}
|
||||
a.hashCode()
|
||||
@@ -37,7 +37,7 @@ fun sideEffectBeforeAssignedInTryAndCatch(s: Any) {
|
||||
a = 42
|
||||
} catch (e: Exception) {
|
||||
s as String // Potential cast exception
|
||||
a = 41
|
||||
<!VAL_REASSIGNMENT!>a<!> = 41
|
||||
} finally {
|
||||
}
|
||||
a.hashCode()
|
||||
@@ -48,9 +48,9 @@ fun assignedAtAll() {
|
||||
try {
|
||||
a = 42
|
||||
} catch (e: Exception) {
|
||||
a = 41
|
||||
<!VAL_REASSIGNMENT!>a<!> = 41
|
||||
} finally {
|
||||
a = 40
|
||||
<!VAL_REASSIGNMENT!>a<!> = 40
|
||||
}
|
||||
a.hashCode()
|
||||
}
|
||||
@@ -62,9 +62,9 @@ fun sideEffectBeforeAssignedInTryCatchButNotFinally(s: Any) {
|
||||
a = 42
|
||||
} catch (e: Exception) {
|
||||
s as String // Potential cast exception
|
||||
a = 41
|
||||
<!VAL_REASSIGNMENT!>a<!> = 41
|
||||
} finally {
|
||||
a = 40
|
||||
<!VAL_REASSIGNMENT!>a<!> = 40
|
||||
}
|
||||
a.hashCode()
|
||||
}
|
||||
|
||||
+2
-2
@@ -22,7 +22,7 @@ fun assignedInTryAndFinally() {
|
||||
try {
|
||||
a = 42
|
||||
} finally {
|
||||
a = 41
|
||||
<!VAL_REASSIGNMENT!>a<!> = 41
|
||||
}
|
||||
a.hashCode()
|
||||
}
|
||||
@@ -33,7 +33,7 @@ fun sideEffectBeforeAssignmentInTryButNotFinally(s: Any) {
|
||||
s as String // Potential cast exception
|
||||
a = 42
|
||||
} finally {
|
||||
a = 41
|
||||
<!VAL_REASSIGNMENT!>a<!> = 41
|
||||
}
|
||||
a.hashCode()
|
||||
}
|
||||
|
||||
-23
@@ -1,23 +0,0 @@
|
||||
// See KT-15334: incorrect reassignment in do...while
|
||||
|
||||
fun test() {
|
||||
do {
|
||||
val s: String
|
||||
s = ""
|
||||
} while (s == "")
|
||||
}
|
||||
|
||||
fun test2() {
|
||||
do {
|
||||
val s: String
|
||||
s = "1"
|
||||
s = s + "2"
|
||||
} while (s == "1")
|
||||
}
|
||||
|
||||
fun test3() {
|
||||
val s: String
|
||||
do {
|
||||
s = ""
|
||||
} while (s != "")
|
||||
}
|
||||
@@ -1,3 +1,4 @@
|
||||
// FIR_IDENTICAL
|
||||
// See KT-15334: incorrect reassignment in do...while
|
||||
|
||||
fun test() {
|
||||
|
||||
+6
-6
@@ -8,7 +8,7 @@ fun f1() {
|
||||
}
|
||||
catch (e: Exception) {
|
||||
// KT-13612: reassignment
|
||||
n = 2
|
||||
<!VAL_REASSIGNMENT!>n<!> = 2
|
||||
}
|
||||
n.hashCode()
|
||||
}
|
||||
@@ -20,7 +20,7 @@ fun f2() {
|
||||
throw Exception()
|
||||
}
|
||||
finally {
|
||||
n = 2
|
||||
<!VAL_REASSIGNMENT!>n<!> = 2
|
||||
}
|
||||
n.hashCode()
|
||||
}
|
||||
@@ -33,7 +33,7 @@ fun g1(flag: Boolean) {
|
||||
}
|
||||
catch (e: Exception) {
|
||||
// KT-13612: ? reassignment or definite assignment ?
|
||||
n = 2
|
||||
<!VAL_REASSIGNMENT!>n<!> = 2
|
||||
}
|
||||
n.hashCode()
|
||||
}
|
||||
@@ -45,7 +45,7 @@ fun g2(flag: Boolean) {
|
||||
n = 1
|
||||
}
|
||||
finally {
|
||||
n = 2
|
||||
<!VAL_REASSIGNMENT!>n<!> = 2
|
||||
}
|
||||
n.hashCode()
|
||||
}
|
||||
@@ -84,7 +84,7 @@ fun k1(flag: Boolean) {
|
||||
}
|
||||
catch (e: Exception) {
|
||||
// KT-13612: reassignment
|
||||
n = 2
|
||||
<!VAL_REASSIGNMENT!>n<!> = 2
|
||||
}
|
||||
n.hashCode()
|
||||
}
|
||||
@@ -96,7 +96,7 @@ fun k2(flag: Boolean) {
|
||||
j(flag)
|
||||
}
|
||||
finally {
|
||||
n = 2
|
||||
<!VAL_REASSIGNMENT!>n<!> = 2
|
||||
}
|
||||
n.hashCode()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user