Correct handling of local class / anonymous object cases for KT-10445 / KT-10042

This commit is contained in:
Mikhail Glukhikh
2016-03-22 14:54:53 +03:00
parent b975b7d26e
commit 32e7f9e58f
3 changed files with 124 additions and 8 deletions
@@ -1,3 +1,5 @@
// !DIAGNOSTICS: -ASSIGNED_BUT_NEVER_ACCESSED_VARIABLE
fun foo() {
var x: String
class A {
@@ -19,3 +21,70 @@ fun bar() {
// 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!
<!VAL_REASSIGNMENT!>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
}