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:
+10
-1
@@ -22,7 +22,6 @@ FILE: reassignOfNonMemberProperty_lateInitialization.kt
|
||||
|
||||
public final val a: R|kotlin/String| = this@R|/Some|.R|kotlin/run|<R|Some|, R|kotlin/String|>(<L> = run@fun R|Some|.<anonymous>(): R|kotlin/String| <inline=Inline, kind=EXACTLY_ONCE> {
|
||||
this@R|special/anonymous|.R|/Some.x| = String(error)
|
||||
this@R|special/anonymous|.R|/Some.y| = String(ok)
|
||||
this@R|special/anonymous|.R|/Some.y| = String(error)
|
||||
this@R|special/anonymous|.R|/z| = String(error)
|
||||
^ String(hello)
|
||||
@@ -30,6 +29,16 @@ FILE: reassignOfNonMemberProperty_lateInitialization.kt
|
||||
)
|
||||
public get(): R|kotlin/String|
|
||||
|
||||
public final val b: R|kotlin/String| = Int(123).R|kotlin/run|<R|kotlin/Int|, R|kotlin/String|>(<L> = run@fun R|kotlin/Int|.<anonymous>(): R|kotlin/String| <inline=Inline, kind=EXACTLY_ONCE> {
|
||||
this@R|/Some|.R|/Some.x| = String(error)
|
||||
this@R|/Some|.R|/Some.y| = String(ok)
|
||||
this@R|/Some|.R|/Some.y| = String(error)
|
||||
this@R|/Some|.R|/z| = String(error)
|
||||
^ String(there)
|
||||
}
|
||||
)
|
||||
public get(): R|kotlin/String|
|
||||
|
||||
init {
|
||||
this@R|/Some|.R|/Some.x| = String(error)
|
||||
this@R|/Some|.R|/Some.y| = String(error)
|
||||
|
||||
Vendored
+10
-1
@@ -15,11 +15,20 @@ class Some {
|
||||
}
|
||||
|
||||
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"
|
||||
"hello"
|
||||
"there"
|
||||
}
|
||||
|
||||
init {
|
||||
|
||||
Reference in New Issue
Block a user