Files
kotlin-fork/compiler/testData/diagnostics/tests/controlFlowAnalysis/kt6788.fir.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

11 lines
259 B
Kotlin
Vendored

class A(val next: A? = null) {
<!MUST_BE_INITIALIZED_OR_BE_ABSTRACT!>val x: String<!>
init {
next?.<!VAL_REASSIGNMENT!>x<!> = "a"
}
}
class B(val next: B? = null) {
var x: String = next?.x ?: "default" // it's ok to use `x` of next
}