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
}
}
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
class A(val next: A? = null) {
|
||||
<!MUST_BE_INITIALIZED_OR_BE_ABSTRACT!>val x: String<!>
|
||||
init {
|
||||
next?.x = "a"
|
||||
next?.<!VAL_REASSIGNMENT!>x<!> = "a"
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Vendored
+2
-2
@@ -1,12 +1,12 @@
|
||||
class A(val next: A? = null) {
|
||||
val x: String
|
||||
init {
|
||||
next?.x = "a"
|
||||
next?.<!VAL_REASSIGNMENT!>x<!> = "a"
|
||||
x = "b"
|
||||
this.x = "c"
|
||||
x = "d" // don't repeat the same diagnostic again with this receiver
|
||||
this.x = "e"
|
||||
|
||||
next?.x = "f"
|
||||
next?.<!VAL_REASSIGNMENT!>x<!> = "f"
|
||||
}
|
||||
}
|
||||
|
||||
Vendored
+1
-1
@@ -15,7 +15,7 @@ class Outer {
|
||||
innerProp = "6" // do not repeat the same diagnostic with this receiver
|
||||
this@Inner.innerProp = "7"
|
||||
|
||||
inner.innerProp = "8"
|
||||
inner.<!VAL_REASSIGNMENT!>innerProp<!> = "8"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+2
-2
@@ -1,12 +1,12 @@
|
||||
class A(val next: A? = null) {
|
||||
val x: String
|
||||
init {
|
||||
next?.x = "a"
|
||||
next?.<!VAL_REASSIGNMENT!>x<!> = "a"
|
||||
this@A.x = "b"
|
||||
this.x = "c"
|
||||
x = "d" // don't repeat the same diagnostic again with this receiver
|
||||
this@A.x = "e"
|
||||
|
||||
next?.x = "f"
|
||||
next?.<!VAL_REASSIGNMENT!>x<!> = "f"
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user