Fix for KT-12200: initial property assignment ignored

#KT-12200 Fixed
This commit is contained in:
Mikhael Bogdanov
2016-05-30 16:00:51 +03:00
parent bdc0b6b308
commit 0f1589fd50
4 changed files with 84 additions and 14 deletions
+30
View File
@@ -0,0 +1,30 @@
//WITH_RUNTIME
class ThingTemplate {
val prop = 0
}
class ThingVal(template: ThingTemplate) {
val prop = template.prop
}
class ThingVar(template: ThingTemplate) {
var prop = template.prop
}
fun box() : String {
val template = ThingTemplate();
val javaClass = ThingTemplate::class.java
val field = javaClass.getDeclaredField("prop")!!
field.isAccessible = true
field.set(template, 1)
val thingVal = ThingVal(template)
if (thingVal.prop != 1) return "fail 1"
val thingVar = ThingVar(template)
if (thingVar.prop != 1) return "fail 2"
return "OK"
}
@@ -0,0 +1,40 @@
//WITH_RUNTIME
//FULL_JDK
//NOTE this test should be removed if Kotlin const properties will became inlined
import java.lang.reflect.Field
import java.lang.reflect.Modifier
object ThingTemplate {
const val prop = 0
}
class ThingVal {
val prop = ThingTemplate.prop
}
class ThingVar {
var prop = ThingTemplate.prop
}
fun box() : String {
val template = ThingTemplate;
val javaClass = ThingTemplate::class.java
val field = javaClass.getDeclaredField("prop")!!
field.isAccessible = true
val modifiersField = Field::class.java!!.getDeclaredField("modifiers")
modifiersField.isAccessible = true
modifiersField.setInt(field, field.modifiers and Modifier.FINAL.inv())
field.set(null, 1)
val thingVal = ThingVal()
if (thingVal.prop != 1) return "fail 1"
val thingVar = ThingVar()
if (thingVar.prop != 1) return "fail 2"
return "OK"
}