[FIR] Add checker for uninitialized properties

This commit is contained in:
Dmitriy Novozhilov
2020-06-17 11:51:15 +03:00
parent 25621d699b
commit 26458875d5
96 changed files with 1476 additions and 1358 deletions
@@ -44,7 +44,7 @@ fun threeLevelsReturnNoInitialization(x: Int?): Int? {
// Possible to report unreachable here
y = 54
}
return y.inc()
return <!UNINITIALIZED_VARIABLE!>y<!>.inc()
}
fun threeLevelsReturnWithInitialization(x: Int?): Int? {
@@ -82,5 +82,5 @@ fun threeLevelsReturnWithUnknown(x: Int?): Int? {
}
}
}
return y.inc()
return <!UNINITIALIZED_VARIABLE!>y<!>.inc()
}
@@ -36,7 +36,7 @@ fun outerFinallyInitializes() {
x = outerComputation()
} catch (e: java.lang.Exception) {
// can catch exception thrown by the inner, so x can be not initialized
x.inc()
<!UNINITIALIZED_VARIABLE!>x<!>.inc()
log()
} finally {
// Possible reassignment (e.g. if everything finished)
@@ -37,7 +37,7 @@ fun innerTryCatchInitializes() {
// Can get here if innerComputation() threw an exception that wasn't catched by the inner catch (x is not initialized)
// OR if outerComputation() threw an exception (x is initialized because we reach outer computation only when inner finished ok)
// So, x=I? here
x.inc()
<!UNINITIALIZED_VARIABLE!>x<!>.inc()
// Potential reasignment
x = 42
@@ -21,7 +21,7 @@ fun withLabeledReturn() {
y = 42
}
println(y)
println(<!UNINITIALIZED_VARIABLE!>y<!>)
println(x)
}
@@ -33,7 +33,7 @@ fun exitOnlyThroughLocalReturns(b: Boolean) {
}
x.inc()
s.length
<!UNINITIALIZED_VARIABLE!>s<!>.length
}
fun exitOnlyThroughNonLocalReturns(b: Boolean?) {
@@ -49,7 +49,7 @@ fun exitOnlyThroughNonLocalReturns(b: Boolean?) {
x = 54
}
if (x == 42) {
if (<!UNINITIALIZED_VARIABLE!>x<!> == 42) {
return
}
else {
@@ -59,8 +59,8 @@ fun exitOnlyThroughNonLocalReturns(b: Boolean?) {
}
}
x.inc()
s.length
<!UNINITIALIZED_VARIABLE!>x<!>.inc()
<!UNINITIALIZED_VARIABLE!>s<!>.length
}
fun nonLocalReturnAndOrdinaryExit(b: Boolean) {
@@ -44,5 +44,5 @@ fun catchThrowIfNotCalled() {
} catch (ignored: java.lang.IllegalArgumentException) { }
// x *isn't* initialized here!
println(x)
println(<!UNINITIALIZED_VARIABLE!>x<!>)
}
@@ -22,7 +22,7 @@ fun tryCatchInlined() {
x.inc()
}
catch (e: java.lang.Exception) {
x.inc()
<!UNINITIALIZED_VARIABLE!>x<!>.inc()
}
}
x = 42