From 655cf8253404e9680ec013aa07443bda68fe2766 Mon Sep 17 00:00:00 2001 From: Mikhail Zarechenskiy Date: Mon, 6 Feb 2017 17:27:57 +0300 Subject: [PATCH] Copy compileTimeInitializer for const property descriptor #KT-15802 Fixed --- .../inlineJavaConstantFromSubclass.kt | 27 +++++++++++++++++++ .../deprecated/javaDeprecatedInheritance.txt | 2 +- .../j+k/collectionOverrides/removeAt.txt | 2 +- .../j+k/collectionOverrides/removeAtInt.txt | 2 +- .../tests/j+k/finalCollectionSize.txt | 4 +-- .../tests/j+k/primitiveOverrides/kt11140.txt | 10 +++---- .../tests/modifiers/const/applicability.txt | 2 +- .../tests/modifiers/const/fromJavaSubclass.kt | 15 +++++++++++ .../modifiers/const/fromJavaSubclass.txt | 24 +++++++++++++++++ .../tests/scopes/inheritance/statics/jjkj.txt | 4 +-- .../scopes/inheritance/statics/nameClash0.txt | 2 +- .../scopes/inheritance/statics/nameClash1.txt | 2 +- .../scopes/inheritance/statics/nameClash2.txt | 6 ++--- .../statics/oneInterfaceManyTimes.txt | 4 +-- .../inheritanceStaticMethodFromInterface.txt | 2 +- .../customClassMutableCollection.txt | 2 +- .../customClassMutableList.txt | 2 +- .../invalidFqName.txt | 4 +-- .../wrongTypeParametersCount.txt | 2 +- .../ClassDoesNotOverrideMethod.txt | 2 +- .../modality/ModalityOfFakeOverrides.txt | 2 +- .../StaticMembersFromParentInterface.txt | 4 +-- .../static/StaticMembersInEnumFromParents.txt | 4 +-- .../checkers/DiagnosticsTestGenerated.java | 6 +++++ .../codegen/BytecodeTextTestGenerated.java | 6 +++++ .../impl/PropertyDescriptorImpl.java | 6 ++++- 26 files changed, 115 insertions(+), 33 deletions(-) create mode 100644 compiler/testData/codegen/bytecodeText/inlineJavaConstantFromSubclass.kt create mode 100644 compiler/testData/diagnostics/tests/modifiers/const/fromJavaSubclass.kt create mode 100644 compiler/testData/diagnostics/tests/modifiers/const/fromJavaSubclass.txt diff --git a/compiler/testData/codegen/bytecodeText/inlineJavaConstantFromSubclass.kt b/compiler/testData/codegen/bytecodeText/inlineJavaConstantFromSubclass.kt new file mode 100644 index 00000000000..7511d6c1903 --- /dev/null +++ b/compiler/testData/codegen/bytecodeText/inlineJavaConstantFromSubclass.kt @@ -0,0 +1,27 @@ +// FILE: first/JavaSuperclass.java + +package first; + +public class JavaSuperclass { + public static final String CONSTANT = "foo"; +} + +// FILE: first/JavaSubclass.java + +package first; + +public class JavaSubclass extends JavaSuperclass { +} + +// FILE: second/bar.kt + +package second + +import first.JavaSubclass + +fun bar() = JavaSubclass.CONSTANT + +// @second/BarKt.class +// 0 INVOKESTATIC +// 0 GETSTATIC +// 1 LDC "foo" \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/deprecated/javaDeprecatedInheritance.txt b/compiler/testData/diagnostics/tests/deprecated/javaDeprecatedInheritance.txt index fe6fde705fb..55458ffaffa 100644 --- a/compiler/testData/diagnostics/tests/deprecated/javaDeprecatedInheritance.txt +++ b/compiler/testData/diagnostics/tests/deprecated/javaDeprecatedInheritance.txt @@ -34,6 +34,6 @@ public open class C : A { public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String // Static members - @kotlin.Deprecated(message = "Deprecated in Java") public const final override /*1*/ /*fake_override*/ val D: kotlin.String + @kotlin.Deprecated(message = "Deprecated in Java") public const final override /*1*/ /*fake_override*/ val D: kotlin.String = "d" @kotlin.Deprecated(message = "Deprecated in Java") public open override /*1*/ /*fake_override*/ fun bar(): kotlin.Unit } diff --git a/compiler/testData/diagnostics/tests/j+k/collectionOverrides/removeAt.txt b/compiler/testData/diagnostics/tests/j+k/collectionOverrides/removeAt.txt index 76ead6f7276..5e630e2f892 100644 --- a/compiler/testData/diagnostics/tests/j+k/collectionOverrides/removeAt.txt +++ b/compiler/testData/diagnostics/tests/j+k/collectionOverrides/removeAt.txt @@ -36,7 +36,7 @@ public abstract class A : B { public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String // Static members - invisible_fake const final override /*1*/ /*fake_override*/ val MAX_ARRAY_SIZE: kotlin.Int + invisible_fake const final override /*1*/ /*fake_override*/ val MAX_ARRAY_SIZE: kotlin.Int = 2147483639 invisible_fake open override /*1*/ /*fake_override*/ fun finishToArray(/*0*/ p0: kotlin.Array<(out) T!>!, /*1*/ p1: kotlin.collections.(Mutable)Iterator<*>!): kotlin.Array<(out) T!>! invisible_fake open override /*1*/ /*fake_override*/ fun hugeCapacity(/*0*/ p0: kotlin.Int): kotlin.Int } diff --git a/compiler/testData/diagnostics/tests/j+k/collectionOverrides/removeAtInt.txt b/compiler/testData/diagnostics/tests/j+k/collectionOverrides/removeAtInt.txt index 9ac8a2eb68c..89cff7b6c76 100644 --- a/compiler/testData/diagnostics/tests/j+k/collectionOverrides/removeAtInt.txt +++ b/compiler/testData/diagnostics/tests/j+k/collectionOverrides/removeAtInt.txt @@ -36,7 +36,7 @@ public abstract class A : B { public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String // Static members - invisible_fake const final override /*1*/ /*fake_override*/ val MAX_ARRAY_SIZE: kotlin.Int + invisible_fake const final override /*1*/ /*fake_override*/ val MAX_ARRAY_SIZE: kotlin.Int = 2147483639 invisible_fake open override /*1*/ /*fake_override*/ fun finishToArray(/*0*/ p0: kotlin.Array<(out) T!>!, /*1*/ p1: kotlin.collections.(Mutable)Iterator<*>!): kotlin.Array<(out) T!>! invisible_fake open override /*1*/ /*fake_override*/ fun hugeCapacity(/*0*/ p0: kotlin.Int): kotlin.Int } diff --git a/compiler/testData/diagnostics/tests/j+k/finalCollectionSize.txt b/compiler/testData/diagnostics/tests/j+k/finalCollectionSize.txt index 9d607f517f3..caf378ea560 100644 --- a/compiler/testData/diagnostics/tests/j+k/finalCollectionSize.txt +++ b/compiler/testData/diagnostics/tests/j+k/finalCollectionSize.txt @@ -47,8 +47,8 @@ public abstract class A : java.util.ArrayList { invisible_fake open override /*1*/ /*fake_override*/ fun writeObject(/*0*/ p0: java.io.ObjectOutputStream!): kotlin.Unit // Static members - invisible_fake const final override /*1*/ /*fake_override*/ val MAX_ARRAY_SIZE: kotlin.Int - invisible_fake const final override /*1*/ /*fake_override*/ val serialVersionUID: kotlin.Long + invisible_fake const final override /*1*/ /*fake_override*/ val MAX_ARRAY_SIZE: kotlin.Int = 2147483639 + invisible_fake const final override /*1*/ /*fake_override*/ val serialVersionUID: kotlin.Long = 8683452581122892189.toLong() invisible_fake open override /*1*/ /*fake_override*/ fun finishToArray(/*0*/ p0: kotlin.Array<(out) T!>!, /*1*/ p1: kotlin.collections.(Mutable)Iterator<*>!): kotlin.Array<(out) T!>! invisible_fake open override /*1*/ /*fake_override*/ fun hugeCapacity(/*0*/ p0: kotlin.Int): kotlin.Int invisible_fake open override /*1*/ /*fake_override*/ fun subListRangeCheck(/*0*/ p0: kotlin.Int, /*1*/ p1: kotlin.Int, /*2*/ p2: kotlin.Int): kotlin.Unit diff --git a/compiler/testData/diagnostics/tests/j+k/primitiveOverrides/kt11140.txt b/compiler/testData/diagnostics/tests/j+k/primitiveOverrides/kt11140.txt index 02afc97d626..afaf2c004da 100644 --- a/compiler/testData/diagnostics/tests/j+k/primitiveOverrides/kt11140.txt +++ b/compiler/testData/diagnostics/tests/j+k/primitiveOverrides/kt11140.txt @@ -55,11 +55,11 @@ public open class A : java.util.HashMap, B finishToArray(/*0*/ p0: kotlin.Array<(out) T!>!, /*1*/ p1: kotlin.collections.(Mutable)Iterator<*>!): kotlin.Array<(out) T!>! invisible_fake open override /*1*/ /*fake_override*/ fun hugeCapacity(/*0*/ p0: kotlin.Int): kotlin.Int } diff --git a/compiler/testData/diagnostics/testsWithStdLib/purelyImplementedCollection/customClassMutableList.txt b/compiler/testData/diagnostics/testsWithStdLib/purelyImplementedCollection/customClassMutableList.txt index ff897dafecd..f9b05ee1b9a 100644 --- a/compiler/testData/diagnostics/testsWithStdLib/purelyImplementedCollection/customClassMutableList.txt +++ b/compiler/testData/diagnostics/testsWithStdLib/purelyImplementedCollection/customClassMutableList.txt @@ -37,7 +37,7 @@ public fun foo(): kotlin.Unit public open override /*2*/ /*fake_override*/ fun toString(): kotlin.String // Static members - invisible_fake const final override /*1*/ /*fake_override*/ val MAX_ARRAY_SIZE: kotlin.Int + invisible_fake const final override /*1*/ /*fake_override*/ val MAX_ARRAY_SIZE: kotlin.Int = 2147483639 invisible_fake open override /*1*/ /*fake_override*/ fun finishToArray(/*0*/ p0: kotlin.Array<(out) T!>!, /*1*/ p1: kotlin.collections.(Mutable)Iterator<*>!): kotlin.Array<(out) T!>! invisible_fake open override /*1*/ /*fake_override*/ fun hugeCapacity(/*0*/ p0: kotlin.Int): kotlin.Int } diff --git a/compiler/testData/diagnostics/testsWithStdLib/purelyImplementedCollection/invalidFqName.txt b/compiler/testData/diagnostics/testsWithStdLib/purelyImplementedCollection/invalidFqName.txt index 16ef1b09dfd..466e3c46309 100644 --- a/compiler/testData/diagnostics/testsWithStdLib/purelyImplementedCollection/invalidFqName.txt +++ b/compiler/testData/diagnostics/testsWithStdLib/purelyImplementedCollection/invalidFqName.txt @@ -37,7 +37,7 @@ public val y: B public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String // Static members - invisible_fake const final override /*1*/ /*fake_override*/ val MAX_ARRAY_SIZE: kotlin.Int + invisible_fake const final override /*1*/ /*fake_override*/ val MAX_ARRAY_SIZE: kotlin.Int = 2147483639 invisible_fake open override /*1*/ /*fake_override*/ fun finishToArray(/*0*/ p0: kotlin.Array<(out) T!>!, /*1*/ p1: kotlin.collections.(Mutable)Iterator<*>!): kotlin.Array<(out) T!>! invisible_fake open override /*1*/ /*fake_override*/ fun hugeCapacity(/*0*/ p0: kotlin.Int): kotlin.Int } @@ -76,7 +76,7 @@ public val y: B public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String // Static members - invisible_fake const final override /*1*/ /*fake_override*/ val MAX_ARRAY_SIZE: kotlin.Int + invisible_fake const final override /*1*/ /*fake_override*/ val MAX_ARRAY_SIZE: kotlin.Int = 2147483639 invisible_fake open override /*1*/ /*fake_override*/ fun finishToArray(/*0*/ p0: kotlin.Array<(out) T!>!, /*1*/ p1: kotlin.collections.(Mutable)Iterator<*>!): kotlin.Array<(out) T!>! invisible_fake open override /*1*/ /*fake_override*/ fun hugeCapacity(/*0*/ p0: kotlin.Int): kotlin.Int } diff --git a/compiler/testData/diagnostics/testsWithStdLib/purelyImplementedCollection/wrongTypeParametersCount.txt b/compiler/testData/diagnostics/testsWithStdLib/purelyImplementedCollection/wrongTypeParametersCount.txt index f29fa3b2cf1..6db85c53cc2 100644 --- a/compiler/testData/diagnostics/testsWithStdLib/purelyImplementedCollection/wrongTypeParametersCount.txt +++ b/compiler/testData/diagnostics/testsWithStdLib/purelyImplementedCollection/wrongTypeParametersCount.txt @@ -37,7 +37,7 @@ public fun foo(): kotlin.Unit public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String // Static members - invisible_fake const final override /*1*/ /*fake_override*/ val MAX_ARRAY_SIZE: kotlin.Int + invisible_fake const final override /*1*/ /*fake_override*/ val MAX_ARRAY_SIZE: kotlin.Int = 2147483639 invisible_fake open override /*1*/ /*fake_override*/ fun finishToArray(/*0*/ p0: kotlin.Array<(out) T!>!, /*1*/ p1: kotlin.collections.(Mutable)Iterator<*>!): kotlin.Array<(out) T!>! invisible_fake open override /*1*/ /*fake_override*/ fun hugeCapacity(/*0*/ p0: kotlin.Int): kotlin.Int } diff --git a/compiler/testData/loadJava/compiledJava/ClassDoesNotOverrideMethod.txt b/compiler/testData/loadJava/compiledJava/ClassDoesNotOverrideMethod.txt index a7ad11dd6e3..2a349bea6ea 100644 --- a/compiler/testData/loadJava/compiledJava/ClassDoesNotOverrideMethod.txt +++ b/compiler/testData/loadJava/compiledJava/ClassDoesNotOverrideMethod.txt @@ -37,7 +37,7 @@ public abstract class ClassDoesNotOverrideMethod : java.util.Date { invisible_fake final override /*1*/ /*fake_override*/ var defaultCenturyStart: kotlin.Int invisible_fake final override /*1*/ /*fake_override*/ val gcal: sun.util.calendar.BaseCalendar! invisible_fake final override /*1*/ /*fake_override*/ var jcal: sun.util.calendar.BaseCalendar! - invisible_fake const final override /*1*/ /*fake_override*/ val serialVersionUID: kotlin.Long + invisible_fake const final override /*1*/ /*fake_override*/ val serialVersionUID: kotlin.Long = 7523967970034938905.toLong() invisible_fake final override /*1*/ /*fake_override*/ val ttb: kotlin.IntArray! invisible_fake final override /*1*/ /*fake_override*/ val wtb: kotlin.Array<(out) kotlin.String!>! @kotlin.Deprecated(message = "Deprecated in Java") public open override /*1*/ /*fake_override*/ fun UTC(/*0*/ p0: kotlin.Int, /*1*/ p1: kotlin.Int, /*2*/ p2: kotlin.Int, /*3*/ p3: kotlin.Int, /*4*/ p4: kotlin.Int, /*5*/ p5: kotlin.Int): kotlin.Long diff --git a/compiler/testData/loadJava/compiledJava/modality/ModalityOfFakeOverrides.txt b/compiler/testData/loadJava/compiledJava/modality/ModalityOfFakeOverrides.txt index 072674f5f53..feeb39b6f00 100644 --- a/compiler/testData/loadJava/compiledJava/modality/ModalityOfFakeOverrides.txt +++ b/compiler/testData/loadJava/compiledJava/modality/ModalityOfFakeOverrides.txt @@ -31,7 +31,7 @@ public open class ModalityOfFakeOverrides : java.util.AbstractList toArray(/*0*/ p0: kotlin.Array<(out) T!>!): kotlin.Array<(out) T!>! // Static members - invisible_fake const final override /*1*/ /*fake_override*/ val MAX_ARRAY_SIZE: kotlin.Int + invisible_fake const final override /*1*/ /*fake_override*/ val MAX_ARRAY_SIZE: kotlin.Int = 2147483639 invisible_fake open override /*1*/ /*fake_override*/ fun finishToArray(/*0*/ p0: kotlin.Array<(out) T!>!, /*1*/ p1: kotlin.collections.(Mutable)Iterator<*>!): kotlin.Array<(out) T!>! invisible_fake open override /*1*/ /*fake_override*/ fun hugeCapacity(/*0*/ p0: kotlin.Int): kotlin.Int } diff --git a/compiler/testData/loadJava/compiledJava/static/StaticMembersFromParentInterface.txt b/compiler/testData/loadJava/compiledJava/static/StaticMembersFromParentInterface.txt index f64578f8efb..e36378a2341 100644 --- a/compiler/testData/loadJava/compiledJava/static/StaticMembersFromParentInterface.txt +++ b/compiler/testData/loadJava/compiledJava/static/StaticMembersFromParentInterface.txt @@ -4,11 +4,11 @@ public/*package*/ open class Child : test.Parent1, test.Parent2 { public/*package*/ constructor Child() // Static members - public const final override /*1*/ /*fake_override*/ val a: kotlin.Int + public const final override /*1*/ /*fake_override*/ val a: kotlin.Int = 1 public final var b: kotlin.String! public final var c: kotlin.Int public final var d: kotlin.String! - public const final override /*1*/ /*fake_override*/ val e: kotlin.Int + public const final override /*1*/ /*fake_override*/ val e: kotlin.Int = 2 public open fun bar(): kotlin.Unit public open fun baz(): kotlin.Unit } diff --git a/compiler/testData/loadJava/compiledJava/static/StaticMembersInEnumFromParents.txt b/compiler/testData/loadJava/compiledJava/static/StaticMembersInEnumFromParents.txt index d03219c7844..9ce3502a615 100644 --- a/compiler/testData/loadJava/compiledJava/static/StaticMembersInEnumFromParents.txt +++ b/compiler/testData/loadJava/compiledJava/static/StaticMembersInEnumFromParents.txt @@ -26,11 +26,11 @@ public/*package*/ final enum class StaticMembersInEnum : kotlin.Enum! // Static members - public const final override /*1*/ /*fake_override*/ val a: kotlin.Int + public const final override /*1*/ /*fake_override*/ val a: kotlin.Int = 1 public final var b: kotlin.Int public final var c: kotlin.Int public final var d: kotlin.Int - public const final override /*1*/ /*fake_override*/ val e: kotlin.Int + public const final override /*1*/ /*fake_override*/ val e: kotlin.Int = 2 public open fun foo(): kotlin.Unit public final /*synthesized*/ fun valueOf(/*0*/ value: kotlin.String): test.StaticMembersInEnum public final /*synthesized*/ fun values(): kotlin.Array diff --git a/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestGenerated.java index dffc01df7e2..8ccebc9cef6 100644 --- a/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestGenerated.java @@ -12531,6 +12531,12 @@ public class DiagnosticsTestGenerated extends AbstractDiagnosticsTest { doTest(fileName); } + @TestMetadata("fromJavaSubclass.kt") + public void testFromJavaSubclass() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/modifiers/const/fromJavaSubclass.kt"); + doTest(fileName); + } + @TestMetadata("noDivisionByZeroFeature.kt") public void testNoDivisionByZeroFeature() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/modifiers/const/noDivisionByZeroFeature.kt"); diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/BytecodeTextTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/BytecodeTextTestGenerated.java index 8c6cf73c774..78c4dd38de8 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/BytecodeTextTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/BytecodeTextTestGenerated.java @@ -138,6 +138,12 @@ public class BytecodeTextTestGenerated extends AbstractBytecodeTextTest { doTest(fileName); } + @TestMetadata("inlineJavaConstantFromSubclass.kt") + public void testInlineJavaConstantFromSubclass() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/bytecodeText/inlineJavaConstantFromSubclass.kt"); + doTest(fileName); + } + @TestMetadata("inlineJavaStaticFields.kt") public void testInlineJavaStaticFields() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/bytecodeText/inlineJavaStaticFields.kt"); diff --git a/core/descriptors/src/org/jetbrains/kotlin/descriptors/impl/PropertyDescriptorImpl.java b/core/descriptors/src/org/jetbrains/kotlin/descriptors/impl/PropertyDescriptorImpl.java index 496f556446d..24e7fd8ca96 100644 --- a/core/descriptors/src/org/jetbrains/kotlin/descriptors/impl/PropertyDescriptorImpl.java +++ b/core/descriptors/src/org/jetbrains/kotlin/descriptors/impl/PropertyDescriptorImpl.java @@ -1,5 +1,5 @@ /* - * Copyright 2010-2016 JetBrains s.r.o. + * Copyright 2010-2017 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -333,6 +333,10 @@ public class PropertyDescriptorImpl extends VariableDescriptorWithInitializerImp substitutedDescriptor.setOverriddenDescriptors(overridden); } + if (isConst() && compileTimeInitializer != null) { + substitutedDescriptor.setCompileTimeInitializer(compileTimeInitializer); + } + return substitutedDescriptor; }