Files
kotlin-fork/compiler/fir/analysis-tests/testData/resolve/cfa/reassignOfNonMemberProperty_lateInitialization.kt
T
pyos c42dd0848e FIR: only allow member val initialization through this@T
class C {
    val x: Int
    init {
      // valid ways to initialize:
      x = 1
      this@C.x = 1
      // invalid:
      someOtherC.x = 1
      run { /*this@run.*/x = 1 }
      val self = this
      self.x = 1
    }
  }
2023-01-26 13:12:12 +00:00

41 lines
793 B
Kotlin
Vendored

// ISSUE: KT-55493
// WITH_STDLIB
val Some.z: String
get() = "ok"
class Some {
val x: String
val y: String
init {
x = "ok"
x = "error"
<!VAL_REASSIGNMENT!>z<!> = "error"
}
val a: String = run {
// these are all on this@run, which is not guaranteed to be this@Some
<!VAL_REASSIGNMENT!>x<!> = "error"
<!VAL_REASSIGNMENT!>y<!> = "error"
<!VAL_REASSIGNMENT!>z<!> = "error"
"hello"
}
val b: String = 123.run {
// now this@run is an Int, so these are on this@Some
x = "error"
y = "ok"
y = "error"
<!VAL_REASSIGNMENT!>z<!> = "error"
"there"
}
init {
x = "error"
y = "error"
<!VAL_REASSIGNMENT!>z<!> = "error"
}
}