FIR: Report CAPTURED_VAL_INITIALIZATION if initialization is done
outside of constructor. In other words, when EXACTLY_ONCE lambda initializes non-static final field of a class, the lambda has to be inlined, otherwise, backend generated separate function of separate class for the lambda, which lead to exception at runtime. #KT-64854 Fixed #KT-59906 Fixed
This commit is contained in:
committed by
Space Team
parent
5dec87eba8
commit
1c4023fda5
+40
-6
@@ -42,19 +42,53 @@ class Test {
|
||||
val b: String
|
||||
val c: String
|
||||
val d: String
|
||||
val e: String
|
||||
<!MUST_BE_INITIALIZED_OR_BE_ABSTRACT!>val f: String<!>
|
||||
<!MUST_BE_INITIALIZED_OR_BE_ABSTRACT!>val g: String<!>
|
||||
val h: String
|
||||
<!MUST_BE_INITIALIZED_OR_BE_ABSTRACT!>val i: String<!>
|
||||
|
||||
init {
|
||||
inlineMe {
|
||||
a = "allowed"
|
||||
}
|
||||
crossinlineMe {
|
||||
b = "not allowed"
|
||||
<!CAPTURED_VAL_INITIALIZATION!>b<!> = "not allowed"
|
||||
}
|
||||
noinlineMe {
|
||||
c = "not allowed"
|
||||
<!CAPTURED_VAL_INITIALIZATION!>c<!> = "not allowed"
|
||||
}
|
||||
notinline {
|
||||
d = "not allowed"
|
||||
<!CAPTURED_VAL_INITIALIZATION!>d<!> = "not allowed"
|
||||
}
|
||||
|
||||
crossinlineMe {
|
||||
inlineMe {
|
||||
<!CAPTURED_VAL_INITIALIZATION!>e<!> = "not allowed"
|
||||
}
|
||||
}
|
||||
|
||||
fun localFun() {
|
||||
<!CAPTURED_MEMBER_VAL_INITIALIZATION!>f<!> = "not allowed"
|
||||
}
|
||||
|
||||
val localLambda = {
|
||||
<!CAPTURED_MEMBER_VAL_INITIALIZATION!>g<!> = "not allowed"
|
||||
}
|
||||
|
||||
object {
|
||||
val o: String
|
||||
|
||||
init {
|
||||
<!CAPTURED_VAL_INITIALIZATION!>h<!> = "not allowed"
|
||||
o = "allowed"
|
||||
}
|
||||
}
|
||||
|
||||
class Local {
|
||||
init {
|
||||
<!CAPTURED_MEMBER_VAL_INITIALIZATION!>i<!> = "not allowed"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -141,12 +175,12 @@ class Test5 {
|
||||
a = "OK"
|
||||
}
|
||||
val bInit = crossinlineMe {
|
||||
b = "OK"
|
||||
<!CAPTURED_VAL_INITIALIZATION!>b<!> = "not allowed"
|
||||
}
|
||||
val cInit = noinlineMe {
|
||||
c = "OK"
|
||||
<!CAPTURED_VAL_INITIALIZATION!>c<!> = "not allowed"
|
||||
}
|
||||
val dInit = notinline {
|
||||
d = "OK"
|
||||
<!CAPTURED_VAL_INITIALIZATION!>d<!> = "not allowed"
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user