NoArg: Do not invoke initializers by default. Require "invokeInitializers" option to be set explicitly (KT-18667, KT-18668)

This commit is contained in:
Yan Zhulanow
2017-07-04 17:18:41 +03:00
committed by Yan Zhulanow
parent a983137978
commit b99007961f
14 changed files with 160 additions and 9 deletions
+1
View File
@@ -1,4 +1,5 @@
// WITH_RUNTIME
// INVOKE_INITIALIZERS
annotation class NoArg
@@ -0,0 +1,30 @@
// WITH_RUNTIME
annotation class NoArg
class Simple(val a: String)
@NoArg
class Test(val a: String) {
val x = 5
val y: Simple? = Simple("Hello, world!")
}
fun box(): String {
try {
val test = Test::class.java.newInstance()
if (test.x != 0) {
return "Bad 5"
}
if (test.y != null) {
return "Bad Hello, world!"
}
return "OK"
} catch (e: Throwable) {
e.printStackTrace()
return "Fail"
}
}
+14
View File
@@ -0,0 +1,14 @@
// WITH_RUNTIME
annotation class NoArg
@NoArg
class Foo(val s1: String) {
val s2: String = ""
val l: List<String> = listOf()
}
fun box(): String {
val instance = Foo::class.java.newInstance()
return "OK"
}
+22
View File
@@ -0,0 +1,22 @@
// WITH_RUNTIME
annotation class NoArg
@NoArg
class AuthenticationConfiguration(tokenExpiresIn: Long) {
var tokenExpiryDate: String?
init {
tokenExpiryDate = tokenExpiresIn.toString()
}
}
fun box(): String {
val instance = AuthenticationConfiguration::class.java.newInstance()
if (instance.tokenExpiryDate != null) {
return "Initializer invoked"
}
return "OK"
}