[FIR] Add checker for uninitialized properties
This commit is contained in:
+4
-4
@@ -31,14 +31,14 @@ fun branchingIndetermineFlow(a: Any?) {
|
||||
myRun { x = 43 }
|
||||
}
|
||||
|
||||
x.inc()
|
||||
<!UNINITIALIZED_VARIABLE!>x<!>.inc()
|
||||
}
|
||||
|
||||
fun nonAnonymousLambdas() {
|
||||
val x: Int
|
||||
val initializer = { x = 42 }
|
||||
myRun(initializer)
|
||||
x.inc()
|
||||
<!UNINITIALIZED_VARIABLE!>x<!>.inc()
|
||||
}
|
||||
|
||||
fun multipleAssignments() {
|
||||
@@ -47,7 +47,7 @@ fun multipleAssignments() {
|
||||
// Val reassignment because we know that repeat's lambda called in-place
|
||||
myRun { x = 42 }
|
||||
}
|
||||
x.inc()
|
||||
<!UNINITIALIZED_VARIABLE!>x<!>.inc()
|
||||
}
|
||||
|
||||
fun funWithUnknownInvocations(block: () -> Unit) = block()
|
||||
@@ -56,7 +56,7 @@ fun nestedIndefiniteAssignment() {
|
||||
val x: Int
|
||||
// Captured val initialization reported, because we don't know anything about funWithUnknownInvocations
|
||||
funWithUnknownInvocations { myRun { x = 42 } }
|
||||
x.inc()
|
||||
<!UNINITIALIZED_VARIABLE!>x<!>.inc()
|
||||
}
|
||||
|
||||
class InitializationForbiddenInNonInitSection {
|
||||
|
||||
+4
-4
@@ -16,7 +16,7 @@ fun indefiniteVarReassignment(n: Int) {
|
||||
repeat(n) {
|
||||
myRun { x = 42 }
|
||||
}
|
||||
x.inc()
|
||||
<!UNINITIALIZED_VARIABLE!>x<!>.inc()
|
||||
}
|
||||
|
||||
fun nonAnonymousLambdas() {
|
||||
@@ -24,7 +24,7 @@ fun nonAnonymousLambdas() {
|
||||
var x: Int
|
||||
val initializer = { x = 42 }
|
||||
myRun(initializer)
|
||||
x.inc()
|
||||
<!UNINITIALIZED_VARIABLE!>x<!>.inc()
|
||||
}
|
||||
|
||||
fun branchingIndetermineFlow(a: Any) {
|
||||
@@ -39,7 +39,7 @@ fun branchingIndetermineFlow(a: Any) {
|
||||
myRun { x = 43 }
|
||||
}
|
||||
|
||||
x.inc()
|
||||
<!UNINITIALIZED_VARIABLE!>x<!>.inc()
|
||||
}
|
||||
|
||||
fun funWithUnknownInvocations(block: () -> Unit) = block()
|
||||
@@ -47,5 +47,5 @@ fun funWithUnknownInvocations(block: () -> Unit) = block()
|
||||
fun nestedIndefiniteAssignment() {
|
||||
val x: Int
|
||||
funWithUnknownInvocations { myRun { x = 42 } }
|
||||
x.inc()
|
||||
<!UNINITIALIZED_VARIABLE!>x<!>.inc()
|
||||
}
|
||||
-28
@@ -1,28 +0,0 @@
|
||||
// !LANGUAGE: +AllowContractsForCustomFunctions +UseCallsInPlaceEffect
|
||||
// !USE_EXPERIMENTAL: kotlin.contracts.ExperimentalContracts
|
||||
// !DIAGNOSTICS: -INVISIBLE_REFERENCE -INVISIBLE_MEMBER
|
||||
|
||||
import kotlin.contracts.*
|
||||
|
||||
fun <T, R> T.myLet(block: (T) -> R): R {
|
||||
contract {
|
||||
callsInPlace(block, InvocationKind.EXACTLY_ONCE)
|
||||
}
|
||||
return block(this)
|
||||
}
|
||||
|
||||
fun initializationWithReceiver(y: String) {
|
||||
val x: Int
|
||||
y.myLet { x = 42 }
|
||||
x.inc()
|
||||
}
|
||||
|
||||
fun initializationWithSafeCall(y: String?) {
|
||||
val x: Int
|
||||
y?.myLet { x = 42 }
|
||||
x.inc()
|
||||
}
|
||||
|
||||
fun sanityCheck(x: Int, y: String): Int {
|
||||
y.let { return x }
|
||||
}
|
||||
+1
@@ -1,3 +1,4 @@
|
||||
// FIR_IDENTICAL
|
||||
// !LANGUAGE: +AllowContractsForCustomFunctions +UseCallsInPlaceEffect
|
||||
// !USE_EXPERIMENTAL: kotlin.contracts.ExperimentalContracts
|
||||
// !DIAGNOSTICS: -INVISIBLE_REFERENCE -INVISIBLE_MEMBER
|
||||
|
||||
Reference in New Issue
Block a user