Don't initialize const properties in constructor
#KT-9532 Fixed
This commit is contained in:
committed by
Michael Bogdanov
parent
7d7d37719b
commit
3452fc8d02
@@ -0,0 +1,30 @@
|
||||
object A {
|
||||
const val a: String = "$"
|
||||
const val b = "1234$a"
|
||||
const val c = 10000
|
||||
|
||||
val bNonConst = "1234$a"
|
||||
val bNullable: String = "1234$a"
|
||||
}
|
||||
|
||||
object B {
|
||||
const val a: String = "$"
|
||||
const val b = "1234$a"
|
||||
const val c = 10000
|
||||
|
||||
val bNonConst = "1234$a"
|
||||
val bNullable: String = "1234$a"
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
if (A.a !== B.a) return "Fail 1: A.a !== B.a"
|
||||
|
||||
if (A.b !== B.b) return "Fail 2: A.b !== B.b"
|
||||
|
||||
if (A.c !== B.c) return "Fail 3: A.c !== B.c"
|
||||
|
||||
if (A.bNonConst === B.bNonConst) return "Fail 5: A.bNonConst == B.bNonConst"
|
||||
if (A.bNullable === B.bNullable) return "Fail 6: A.bNullable == B.bNullable"
|
||||
|
||||
return "OK"
|
||||
}
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
|
||||
public class JavaClass {
|
||||
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@interface Foo {
|
||||
int value();
|
||||
}
|
||||
|
||||
@Foo(KotlinInterface.FOO_INT)
|
||||
public String test() throws NoSuchMethodException {
|
||||
return KotlinInterface.FOO_STRING +
|
||||
JavaClass.class.getMethod("test").getAnnotation(Foo.class).value();
|
||||
}
|
||||
}
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
interface KotlinInterface {
|
||||
companion object {
|
||||
const val FOO_INT: Int = 10
|
||||
const val FOO_STRING: String = "OK"
|
||||
}
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
val test = JavaClass().test()
|
||||
return if (test == "OK10") "OK" else "fail : $test"
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
interface KInt {
|
||||
|
||||
companion object {
|
||||
const val a = "a"
|
||||
const val b = "b$a"
|
||||
}
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
val a = KInt::class.java.getField("a").get(null)
|
||||
val b = KInt::class.java.getField("b").get(null)
|
||||
|
||||
if (a !== KInt.a) return "fail 1: KInt.a !== KInt.Companion.a"
|
||||
if (b !== KInt.b) return "fail 2: KInt.b !== KInt.Companion.b"
|
||||
if (b !== "ba") return "fail 2: 'ba' !== KInt.Companion.b"
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
object A {
|
||||
private const val a = "$"
|
||||
private const val b = "1234$a"
|
||||
private const val c = 10000
|
||||
}
|
||||
|
||||
//check that constant initializers inlined
|
||||
|
||||
// 0 GETSTATIC
|
||||
// 2 PUTSTATIC A.INSTANCE
|
||||
Reference in New Issue
Block a user