[JVM IR] Fix issue where fields are not being set to their default
values within initializer blocks.
The issue occurs in code like this:
```
class C {
var b = true
init {
b = false // Missing PUTFIELD for this statement
}
}
```
Added a new statement origin for field initialization (at declaration)
instead of relying on `origin == null` in ExpressionCodegen to determine
whether to generate the initializations.
This was unintentionally broken in
d68a1898d0.
This commit is contained in:
committed by
Dmitry Petrov
parent
56c819f06e
commit
64141b8b38
@@ -0,0 +1,33 @@
|
||||
object C {
|
||||
var myIntProp: Int = 1
|
||||
var myByteProp: Byte = 2
|
||||
var myLongProp: Long = 3L
|
||||
var myShortProp: Short = 4
|
||||
var myDoubleProp: Double = 5.6
|
||||
var myFloatProp: Float = 7.8f
|
||||
var myBooleanProp: Boolean = true
|
||||
var myCharProp: Char = '9'
|
||||
|
||||
init {
|
||||
myIntProp = 0
|
||||
myByteProp = 0
|
||||
myLongProp = 0L
|
||||
myShortProp = 0
|
||||
myDoubleProp = 0.0
|
||||
myFloatProp = 0.0f
|
||||
myBooleanProp = false
|
||||
myCharProp = '\u0000'
|
||||
}
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
if (C.myIntProp != 0) return "fail Int"
|
||||
if (C.myByteProp != 0.toByte()) return "fail Byte"
|
||||
if (C.myLongProp != 0L) return "fail Long"
|
||||
if (C.myShortProp != 0.toShort()) return "fail Short"
|
||||
if (C.myDoubleProp != 0.0) return "fail Double"
|
||||
if (C.myFloatProp != 0.0f) return "fail Float"
|
||||
if (C.myBooleanProp != false) return "fail Boolean"
|
||||
if (C.myCharProp != '\u0000') return "fail Char"
|
||||
return "OK"
|
||||
}
|
||||
Reference in New Issue
Block a user