blob: a7678dfeccea43a29c3d04886e4d23fd01d36495 [file]
// RUN_PIPELINE_TILL: FRONTEND
// DIAGNOSTICS: -ASSIGNED_BUT_NEVER_ACCESSED_VARIABLE
fun foo() {
var x: String
class A {
init {
x = ""
}
}
// Error! See KT-10042
<!UNINITIALIZED_VARIABLE!>x<!>.length
}
fun bar() {
var x: String
object: Any() {
init {
x = ""
}
}
// Ok
x.length
}
fun gav() {
val x: String
class B {
init {
// Error! See KT-10445
<!CAPTURED_VAL_INITIALIZATION!>x<!> = ""
}
}
// Error! See KT-10042
<!UNINITIALIZED_VARIABLE!>x<!>.length
val y: String
class C(val s: String) {
constructor(): this("") {
// Error!
<!CAPTURED_VAL_INITIALIZATION!>y<!> = s
}
}
<!UNINITIALIZED_VARIABLE!>y<!>.length
}
open class Gau(val s: String)
fun gau() {
val x: String
object: Any() {
init {
// Ok
x = ""
}
}
// Ok
x.length
val y: String
fun local() {
object: Any() {
init {
// Error!
<!CAPTURED_VAL_INITIALIZATION!>y<!> = ""
}
}
}
val z: String
object: Gau(if (true) {
z = ""
z
}
else "") {}
}
class My {
init {
val x: String
class Your {
init {
// Error! See KT-10445
<!CAPTURED_VAL_INITIALIZATION!>x<!> = ""
}
}
}
}
<!MUST_BE_INITIALIZED!>val top: Int<!>
fun init() {
<!VAL_REASSIGNMENT!>top<!> = 1
}
// A local property declared inside a member of a local class. The class graph is a sub-graph of the 'localClassMember' graph, and the
// class is not analyzed on its own because of that, so 'q' is only reachable by traversing into the class.
fun localClassMember() {
class D {
val p: Int
init {
val q: Int
q = 1
<!VAL_REASSIGNMENT!>q<!> = 2
p = q
}
}
}
/* GENERATED_FIR_TAGS: anonymousObjectExpression, assignment, classDeclaration, functionDeclaration, ifExpression, init,
integerLiteral, localClass, localFunction, localProperty, primaryConstructor, propertyDeclaration, secondaryConstructor,
stringLiteral */