Files
kotlin/compiler/testData/diagnostics/tests/controlFlowAnalysis/referenceToPropertyInitializer.kt
Mikhail Glukhikh fe13f39de9 Use of uninitialized variables in lambdas / object literals / local functions is forbidden now #KT-4475 Fixed
Local declarations CFA: variable initialization information before them is now taken into account
2015-11-17 18:21:09 +03:00

33 lines
809 B
Kotlin
Vendored

// !DIAGNOSTICS: -UNUSED_VARIABLE
package o
class TestFunctionLiteral {
val sum: (Int) -> Int = { x: Int ->
<!UNINITIALIZED_VARIABLE!>sum<!>(x - 1) + x
}
val foo: () -> Unit = l@ ({ <!UNINITIALIZED_VARIABLE!>foo<!>() })
}
open class A(val a: A)
class TestObjectLiteral {
val obj: A = object: A(<!UNINITIALIZED_VARIABLE!>obj<!>) {
init {
val x = <!UNINITIALIZED_VARIABLE!>obj<!>
}
fun foo() {
val y = <!UNINITIALIZED_VARIABLE!>obj<!>
}
}
val obj1: A = l@ ( object: A(<!UNINITIALIZED_VARIABLE!>obj1<!>) {
init {
val x = <!UNINITIALIZED_VARIABLE!>obj1<!>
}
fun foo() = <!UNINITIALIZED_VARIABLE!>obj1<!>
})
}
class TestOther {
val x: Int = <!UNINITIALIZED_VARIABLE!>x<!> + 1
}