From 79c300209ec9597ac8c011d1464fabcbb94e8fe7 Mon Sep 17 00:00:00 2001 From: Ivan Kylchik Date: Wed, 29 Nov 2023 18:00:49 +0100 Subject: [PATCH] [K2] Avoid type check for Kotlin's property in `ConstUtils` When we check Java field for constant initializer, we could be asked to get and check the type of Kotlin's property that is used in this Java field. But there is no guarantee that the type resolve phase was finished and this type is available. So we just check for `const` modifier and skip type check. #KT-63752 Fixed #KT-62558 Obsolete #KT-61786 Declined --- ...CompilerTestFE10TestdataTestGenerated.java | 6 ++ ...sticCompilerFE10TestDataTestGenerated.java | 6 ++ .../fields/SymbolLightFieldForProperty.kt | 7 +- .../java/FirTypeEnhancementTestGenerated.java | 5 ++ ...eeOldFrontendDiagnosticsTestGenerated.java | 6 ++ ...siOldFrontendDiagnosticsTestGenerated.java | 6 ++ .../java/enhancement/SignatureEnhancement.kt | 2 +- .../org/jetbrains/kotlin/util/ConstUtils.java | 50 ++++++++++++--- .../tests/modifiers/const/kotlinJavaCycle.kt | 3 - .../tests/modifiers/const/kt12248.kt | 2 - ...tlinJavaCycle.fir.kt => noConstKt12248.kt} | 9 ++- .../tests/modifiers/const/noConstKt12248.txt | 41 ++++++++++++ .../static/StaticFinalConstTypes.fir.txt | 64 +++++++++++++++++++ .../static/StaticFinalConstTypes.java | 45 +++++++++++++ .../static/StaticFinalConstTypes.txt | 37 +++++++++++ .../test/runners/DiagnosticTestGenerated.java | 6 ++ .../jvm/compiler/LoadJavaTestGenerated.java | 5 ++ ...dJavaWithPsiClassReadingTestGenerated.java | 5 ++ .../compiler/ir/IrLoadJavaTestGenerated.java | 5 ++ .../LoadJavaUsingJavacTestGenerated.java | 5 ++ ...mRuntimeDescriptorLoaderTestGenerated.java | 5 ++ 21 files changed, 298 insertions(+), 22 deletions(-) rename compiler/testData/diagnostics/tests/modifiers/const/{kotlinJavaCycle.fir.kt => noConstKt12248.kt} (52%) create mode 100644 compiler/testData/diagnostics/tests/modifiers/const/noConstKt12248.txt create mode 100644 compiler/testData/loadJava/compiledJava/static/StaticFinalConstTypes.fir.txt create mode 100644 compiler/testData/loadJava/compiledJava/static/StaticFinalConstTypes.java create mode 100644 compiler/testData/loadJava/compiledJava/static/StaticFinalConstTypes.txt diff --git a/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/DiagnosticCompilerTestFE10TestdataTestGenerated.java b/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/DiagnosticCompilerTestFE10TestdataTestGenerated.java index 7d5f5fffa50..f9c90b84a30 100644 --- a/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/DiagnosticCompilerTestFE10TestdataTestGenerated.java +++ b/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/DiagnosticCompilerTestFE10TestdataTestGenerated.java @@ -23705,6 +23705,12 @@ public class DiagnosticCompilerTestFE10TestdataTestGenerated extends AbstractDia runTest("compiler/testData/diagnostics/tests/modifiers/const/kt57802.kt"); } + @Test + @TestMetadata("noConstKt12248.kt") + public void testNoConstKt12248() throws Exception { + runTest("compiler/testData/diagnostics/tests/modifiers/const/noConstKt12248.kt"); + } + @Test @TestMetadata("stdlibConstFun.kt") public void testStdlibConstFun() throws Exception { diff --git a/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/LLFirPreresolvedReversedDiagnosticCompilerFE10TestDataTestGenerated.java b/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/LLFirPreresolvedReversedDiagnosticCompilerFE10TestDataTestGenerated.java index 3656e49e719..531ef7734fc 100644 --- a/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/LLFirPreresolvedReversedDiagnosticCompilerFE10TestDataTestGenerated.java +++ b/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/LLFirPreresolvedReversedDiagnosticCompilerFE10TestDataTestGenerated.java @@ -23705,6 +23705,12 @@ public class LLFirPreresolvedReversedDiagnosticCompilerFE10TestDataTestGenerated runTest("compiler/testData/diagnostics/tests/modifiers/const/kt57802.kt"); } + @Test + @TestMetadata("noConstKt12248.kt") + public void testNoConstKt12248() throws Exception { + runTest("compiler/testData/diagnostics/tests/modifiers/const/noConstKt12248.kt"); + } + @Test @TestMetadata("stdlibConstFun.kt") public void testStdlibConstFun() throws Exception { diff --git a/analysis/symbol-light-classes/src/org/jetbrains/kotlin/light/classes/symbol/fields/SymbolLightFieldForProperty.kt b/analysis/symbol-light-classes/src/org/jetbrains/kotlin/light/classes/symbol/fields/SymbolLightFieldForProperty.kt index 89423e8eee5..53c794413fe 100644 --- a/analysis/symbol-light-classes/src/org/jetbrains/kotlin/light/classes/symbol/fields/SymbolLightFieldForProperty.kt +++ b/analysis/symbol-light-classes/src/org/jetbrains/kotlin/light/classes/symbol/fields/SymbolLightFieldForProperty.kt @@ -27,6 +27,7 @@ import org.jetbrains.kotlin.light.classes.symbol.classes.SymbolLightClassBase import org.jetbrains.kotlin.light.classes.symbol.modifierLists.GranularModifiersBox import org.jetbrains.kotlin.light.classes.symbol.modifierLists.SymbolLightMemberModifierList import org.jetbrains.kotlin.light.classes.symbol.modifierLists.with +import org.jetbrains.kotlin.load.java.structure.impl.NotEvaluatedConstAware import org.jetbrains.kotlin.name.JvmStandardClassIds.TRANSIENT_ANNOTATION_CLASS_ID import org.jetbrains.kotlin.name.JvmStandardClassIds.VOLATILE_ANNOTATION_CLASS_ID import org.jetbrains.kotlin.psi.KtCallableDeclaration @@ -41,7 +42,7 @@ internal class SymbolLightFieldForProperty private constructor( private val isStatic: Boolean, override val kotlinOrigin: KtCallableDeclaration?, private val backingFieldSymbolPointer: KtSymbolPointer?, -) : SymbolLightField(containingClass, lightMemberOrigin) { +) : SymbolLightField(containingClass, lightMemberOrigin), NotEvaluatedConstAware { internal constructor( ktAnalysisSession: KtAnalysisSession, propertySymbol: KtPropertySymbol, @@ -231,6 +232,10 @@ internal class SymbolLightFieldForProperty private constructor( override fun computeConstantValue(): Any? = _constantValue + override fun isNotYetComputed(): Boolean { + return withPropertySymbol { propertySymbol -> (propertySymbol as? KtKotlinPropertySymbol)?.isConst == true } + } + override fun equals(other: Any?): Boolean { if (this === other) return true if (other !is SymbolLightFieldForProperty || other.ktModule != ktModule || other.fieldName != fieldName) return false diff --git a/compiler/fir/analysis-tests/legacy-fir-tests/tests-gen/org/jetbrains/kotlin/fir/java/FirTypeEnhancementTestGenerated.java b/compiler/fir/analysis-tests/legacy-fir-tests/tests-gen/org/jetbrains/kotlin/fir/java/FirTypeEnhancementTestGenerated.java index 2593d98d8cc..07e728a7a3f 100644 --- a/compiler/fir/analysis-tests/legacy-fir-tests/tests-gen/org/jetbrains/kotlin/fir/java/FirTypeEnhancementTestGenerated.java +++ b/compiler/fir/analysis-tests/legacy-fir-tests/tests-gen/org/jetbrains/kotlin/fir/java/FirTypeEnhancementTestGenerated.java @@ -1594,6 +1594,11 @@ public class FirTypeEnhancementTestGenerated extends AbstractFirTypeEnhancementT runTest("compiler/testData/loadJava/compiledJava/static/StaticFinal.java"); } + @TestMetadata("StaticFinalConstTypes.java") + public void testStaticFinalConstTypes() throws Exception { + runTest("compiler/testData/loadJava/compiledJava/static/StaticFinalConstTypes.java"); + } + @TestMetadata("StaticMembersFromParentClass.java") public void testStaticMembersFromParentClass() throws Exception { runTest("compiler/testData/loadJava/compiledJava/static/StaticMembersFromParentClass.java"); diff --git a/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirLightTreeOldFrontendDiagnosticsTestGenerated.java b/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirLightTreeOldFrontendDiagnosticsTestGenerated.java index 2e61fca1cea..21868736656 100644 --- a/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirLightTreeOldFrontendDiagnosticsTestGenerated.java +++ b/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirLightTreeOldFrontendDiagnosticsTestGenerated.java @@ -23699,6 +23699,12 @@ public class FirLightTreeOldFrontendDiagnosticsTestGenerated extends AbstractFir runTest("compiler/testData/diagnostics/tests/modifiers/const/kt57802.kt"); } + @Test + @TestMetadata("noConstKt12248.kt") + public void testNoConstKt12248() throws Exception { + runTest("compiler/testData/diagnostics/tests/modifiers/const/noConstKt12248.kt"); + } + @Test @TestMetadata("stdlibConstFun.kt") public void testStdlibConstFun() throws Exception { diff --git a/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirPsiOldFrontendDiagnosticsTestGenerated.java b/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirPsiOldFrontendDiagnosticsTestGenerated.java index 0e904b89652..7a246ea7894 100644 --- a/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirPsiOldFrontendDiagnosticsTestGenerated.java +++ b/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirPsiOldFrontendDiagnosticsTestGenerated.java @@ -23705,6 +23705,12 @@ public class FirPsiOldFrontendDiagnosticsTestGenerated extends AbstractFirPsiDia runTest("compiler/testData/diagnostics/tests/modifiers/const/kt57802.kt"); } + @Test + @TestMetadata("noConstKt12248.kt") + public void testNoConstKt12248() throws Exception { + runTest("compiler/testData/diagnostics/tests/modifiers/const/noConstKt12248.kt"); + } + @Test @TestMetadata("stdlibConstFun.kt") public void testStdlibConstFun() throws Exception { diff --git a/compiler/fir/java/src/org/jetbrains/kotlin/fir/java/enhancement/SignatureEnhancement.kt b/compiler/fir/java/src/org/jetbrains/kotlin/fir/java/enhancement/SignatureEnhancement.kt index 51188e7a3de..4a306d884de 100644 --- a/compiler/fir/java/src/org/jetbrains/kotlin/fir/java/enhancement/SignatureEnhancement.kt +++ b/compiler/fir/java/src/org/jetbrains/kotlin/fir/java/enhancement/SignatureEnhancement.kt @@ -125,7 +125,7 @@ class FirSignatureEnhancement( predefinedEnhancementInfo = null ).let { val lowerBound = it.type.lowerBoundIfFlexible() - if ((lowerBound.isString || lowerBound.isInt) && firElement.isStatic && firElement.hasConstantInitializer) { + if (lowerBound.isString && firElement.isStatic && firElement.hasConstantInitializer) { it.withReplacedConeType(it.type.withNullability(ConeNullability.NOT_NULL, session.typeContext)) } else { it diff --git a/compiler/resolution.common.jvm/src/org/jetbrains/kotlin/util/ConstUtils.java b/compiler/resolution.common.jvm/src/org/jetbrains/kotlin/util/ConstUtils.java index 9f4c9e0c095..6fdb1cfdbab 100644 --- a/compiler/resolution.common.jvm/src/org/jetbrains/kotlin/util/ConstUtils.java +++ b/compiler/resolution.common.jvm/src/org/jetbrains/kotlin/util/ConstUtils.java @@ -39,7 +39,10 @@ public class ConstUtils { // Copy of `com.intellij.psi.util.IsConstantExpressionVisitor`. // This copy is required to be able to handle K2 constants without triggering constant evaluation. -// The only change is done in `visitReferenceExpression` where we check for constant expression without triggering evaluation. +// There are two major changes: +// 1. In `visitReferenceExpression` where we check for constant expression without triggering evaluation. +// 2. In `visitPolyadicExpression` before we check for the type. +// At the moment when we check for constant, not all types could be resolved, and if we return a wrong type, it will be cached. final class IsConstantExpressionVisitor extends JavaElementVisitor { private boolean myIsConstant; private final Map varIsConst = new HashMap<>(); @@ -85,6 +88,7 @@ final class IsConstantExpressionVisitor extends JavaElementVisitor { myIsConstant = false; return; } + PsiType type = element.getType(); if (type instanceof PsiPrimitiveType) return; if (type.equalsToText(CommonClassNames.JAVA_LANG_STRING)) return; @@ -112,6 +116,11 @@ final class IsConstantExpressionVisitor extends JavaElementVisitor { for (PsiExpression operand : expression.getOperands()) { operand.accept(this); if (!myIsConstant) return; + + // CHANGE #1 + if (checkForNotYetEvaluatedConstant(operand)) return; + // END + final PsiType type = operand.getType(); if (type != null && !(type instanceof PsiPrimitiveType) && !type.equalsToText(CommonClassNames.JAVA_LANG_STRING)) { myIsConstant = false; @@ -165,15 +174,8 @@ final class IsConstantExpressionVisitor extends JavaElementVisitor { return; } - // This block is the only difference with the original `IsConstantExpressionVisitor` - if (variable instanceof ClsFieldImpl) { - PsiFieldStub stub = ((ClsFieldImpl) variable).getStub(); - if (stub instanceof NotEvaluatedConstAware && ((NotEvaluatedConstAware) stub).isNotYetComputed()) { - myIsConstant = true; - varIsConst.put(variable, Boolean.TRUE); - return; - } - } + // CHANGE #2 + if (checkForNotYetEvaluatedConstant(expression)) return; // END variable.hasInitializer(); @@ -185,4 +187,32 @@ final class IsConstantExpressionVisitor extends JavaElementVisitor { initializer.accept(this); varIsConst.put(variable, myIsConstant); } + + private boolean checkForNotYetEvaluatedConstant(PsiExpression operand) { + if (operand instanceof PsiReferenceExpression) { + PsiElement refElement = ((PsiReferenceExpression) operand).resolve(); + NotEvaluatedConstAware notEvaluatedConstAware = getNotEvaluatedConstAware(refElement); + if (notEvaluatedConstAware != null) { + if (notEvaluatedConstAware.isNotYetComputed()) { + myIsConstant = true; + varIsConst.put((PsiVariable) refElement, Boolean.TRUE); + } + return true; + } + } + return false; + } + + @Nullable + private static NotEvaluatedConstAware getNotEvaluatedConstAware(PsiElement refElement) { + if (refElement instanceof ClsFieldImpl) { + PsiFieldStub stub = ((ClsFieldImpl) refElement).getStub(); + if (stub instanceof NotEvaluatedConstAware) { + return (NotEvaluatedConstAware) stub; + } + } else if (refElement instanceof NotEvaluatedConstAware) { + return (NotEvaluatedConstAware) refElement; + } + return null; + } } diff --git a/compiler/testData/diagnostics/tests/modifiers/const/kotlinJavaCycle.kt b/compiler/testData/diagnostics/tests/modifiers/const/kotlinJavaCycle.kt index 3acec877d90..e3cebe52216 100644 --- a/compiler/testData/diagnostics/tests/modifiers/const/kotlinJavaCycle.kt +++ b/compiler/testData/diagnostics/tests/modifiers/const/kotlinJavaCycle.kt @@ -1,6 +1,3 @@ -// IGNORE_REVERSED_RESOLVE -// IGNORE_CONTRACT_VIOLATIONS -// See KT-63752 about ignores // FIR_IDENTICAL // FILE: Bar.java diff --git a/compiler/testData/diagnostics/tests/modifiers/const/kt12248.kt b/compiler/testData/diagnostics/tests/modifiers/const/kt12248.kt index a93496a207b..51711f7fef2 100644 --- a/compiler/testData/diagnostics/tests/modifiers/const/kt12248.kt +++ b/compiler/testData/diagnostics/tests/modifiers/const/kt12248.kt @@ -1,5 +1,3 @@ -// IGNORE_REVERSED_RESOLVE -// IGNORE_CONTRACT_VIOLATIONS // FIR_IDENTICAL // FILE: Bar.java diff --git a/compiler/testData/diagnostics/tests/modifiers/const/kotlinJavaCycle.fir.kt b/compiler/testData/diagnostics/tests/modifiers/const/noConstKt12248.kt similarity index 52% rename from compiler/testData/diagnostics/tests/modifiers/const/kotlinJavaCycle.fir.kt rename to compiler/testData/diagnostics/tests/modifiers/const/noConstKt12248.kt index 0a0039e972e..093ed77dba7 100644 --- a/compiler/testData/diagnostics/tests/modifiers/const/kotlinJavaCycle.fir.kt +++ b/compiler/testData/diagnostics/tests/modifiers/const/noConstKt12248.kt @@ -1,5 +1,4 @@ -// IGNORE_REVERSED_RESOLVE -// IGNORE_CONTRACT_VIOLATIONS +// FIR_IDENTICAL // FILE: Bar.java public class Bar { @@ -10,12 +9,12 @@ public class Bar { class Foo { companion object { - const val FOO = Baz.BAZ + 1 + val FOO = Baz.BAZ + 1 } } class Baz { companion object { - const val BAZ = Bar.BAR + 1 + val BAZ = Bar.BAR + 1 } -} +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/modifiers/const/noConstKt12248.txt b/compiler/testData/diagnostics/tests/modifiers/const/noConstKt12248.txt new file mode 100644 index 00000000000..e6634063a84 --- /dev/null +++ b/compiler/testData/diagnostics/tests/modifiers/const/noConstKt12248.txt @@ -0,0 +1,41 @@ +package + +public open class Bar { + public constructor Bar() + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String + + // Static members + public const final val BAR: kotlin.Int +} + +public final class Baz { + public constructor Baz() + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String + + public companion object Companion { + private constructor Companion() + public final val BAZ: kotlin.Int + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String + } +} + +public final class Foo { + public constructor Foo() + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String + + public companion object Companion { + private constructor Companion() + public final val FOO: kotlin.Int + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String + } +} diff --git a/compiler/testData/loadJava/compiledJava/static/StaticFinalConstTypes.fir.txt b/compiler/testData/loadJava/compiledJava/static/StaticFinalConstTypes.fir.txt new file mode 100644 index 00000000000..c5cc3b05e47 --- /dev/null +++ b/compiler/testData/loadJava/compiledJava/static/StaticFinalConstTypes.fir.txt @@ -0,0 +1,64 @@ +public open class StaticFinalConstTypes : R|kotlin/Any| { + public final static field stringField: R|kotlin/String| = String(0) + + public final static field stringFieldNull: R|kotlin/String!| + + public final static field booleanField: R|kotlin/Boolean!| + + public final static field booleanFieldNull: R|kotlin/Boolean!| + + public final static field booleanPrimitiveField: R|kotlin/Boolean| = Boolean(false) + + public final static field characterField: R|kotlin/Char!| + + public final static field characterFieldNull: R|kotlin/Char!| + + public final static field characterPrimitiveField: R|kotlin/Char| = Char(0) + + public final static field byteField: R|kotlin/Byte!| + + public final static field byteFieldNull: R|kotlin/Byte!| + + public final static field bytePrimitiveField: R|kotlin/Byte| = Byte(0) + + public final static field shortField: R|kotlin/Short!| + + public final static field shortFieldNull: R|kotlin/Short!| + + public final static field shortPrimitiveField: R|kotlin/Short| = Short(0) + + public final static field integerField: R|kotlin/Int!| + + public final static field integerFieldNull: R|kotlin/Int!| + + public final static field integerPrimitiveField: R|kotlin/Int| = Int(0) + + public final static field longField: R|kotlin/Long!| + + public final static field longFieldNull: R|kotlin/Long!| + + public final static field longPrimitiveField: R|kotlin/Long| = Long(0) + + public final static field floatField: R|kotlin/Float!| + + public final static field floatFieldNull: R|kotlin/Float!| + + public final static field floatPrimitiveField: R|kotlin/Float| = Float(0.0) + + public final static field doubleField: R|kotlin/Double!| + + public final static field doubleFieldNull: R|kotlin/Double!| + + public final static field doublePrimitiveField: R|kotlin/Double| = Double(0.0) + + public final static field uByteField: R|kotlin/UByte!| + + public final static field uShortField: R|kotlin/UShort!| + + public final static field uIntField: R|kotlin/UInt!| + + public final static field uLongField: R|kotlin/ULong!| + + public constructor(): R|test/StaticFinalConstTypes| + +} diff --git a/compiler/testData/loadJava/compiledJava/static/StaticFinalConstTypes.java b/compiler/testData/loadJava/compiledJava/static/StaticFinalConstTypes.java new file mode 100644 index 00000000000..bdb0d7e8d4c --- /dev/null +++ b/compiler/testData/loadJava/compiledJava/static/StaticFinalConstTypes.java @@ -0,0 +1,45 @@ +// SKIP_IN_RUNTIME_TEST because there's no stable way to determine if a field is initialized with a non-null value in runtime + +package test; + +public class StaticFinalConstTypes { + public static final String stringField = "0"; + public static final String stringFieldNull = null; + + public static final Boolean booleanField = false; + public static final Boolean booleanFieldNull = null; + public static final boolean booleanPrimitiveField = false; + + public static final Character characterField = '0'; + public static final Character characterFieldNull = null; + public static final char characterPrimitiveField = '0'; + + public static final Byte byteField = (byte) 0; + public static final Byte byteFieldNull = null; + public static final byte bytePrimitiveField = (byte) 0; + + public static final Short shortField = (short) 0; + public static final Short shortFieldNull = null; + public static final short shortPrimitiveField = (short) 0; + + public static final Integer integerField = 0; + public static final Integer integerFieldNull = null; + public static final int integerPrimitiveField = 0; + + public static final Long longField = 0L; + public static final Long longFieldNull = null; + public static final long longPrimitiveField = 0L; + + public static final Float floatField = 0.0f; + public static final Float floatFieldNull = null; + public static final float floatPrimitiveField = 0.0f; + + public static final Double doubleField = 0.0; + public static final Double doubleFieldNull = null; + public static final double doublePrimitiveField = 0.0; + + public static final kotlin.UByte uByteField = null; + public static final kotlin.UShort uShortField = null; + public static final kotlin.UInt uIntField = null; + public static final kotlin.ULong uLongField = null; +} diff --git a/compiler/testData/loadJava/compiledJava/static/StaticFinalConstTypes.txt b/compiler/testData/loadJava/compiledJava/static/StaticFinalConstTypes.txt new file mode 100644 index 00000000000..b6fef303e22 --- /dev/null +++ b/compiler/testData/loadJava/compiledJava/static/StaticFinalConstTypes.txt @@ -0,0 +1,37 @@ +package test + +public open class StaticFinalConstTypes { + public constructor StaticFinalConstTypes() + + // Static members + public final val booleanField: kotlin.Boolean! + public final val booleanFieldNull: kotlin.Boolean! + public const final val booleanPrimitiveField: kotlin.Boolean = false + public final val byteField: kotlin.Byte! + public final val byteFieldNull: kotlin.Byte! + public const final val bytePrimitiveField: kotlin.Byte = 0.toByte() + public final val characterField: kotlin.Char! + public final val characterFieldNull: kotlin.Char! + public const final val characterPrimitiveField: kotlin.Char = \u0030 ('0') + public final val doubleField: kotlin.Double! + public final val doubleFieldNull: kotlin.Double! + public const final val doublePrimitiveField: kotlin.Double = 0.0.toDouble() + public final val floatField: kotlin.Float! + public final val floatFieldNull: kotlin.Float! + public const final val floatPrimitiveField: kotlin.Float = 0.0.toFloat() + public final val integerField: kotlin.Int! + public final val integerFieldNull: kotlin.Int! + public const final val integerPrimitiveField: kotlin.Int = 0 + public final val longField: kotlin.Long! + public final val longFieldNull: kotlin.Long! + public const final val longPrimitiveField: kotlin.Long = 0.toLong() + public final val shortField: kotlin.Short! + public final val shortFieldNull: kotlin.Short! + public const final val shortPrimitiveField: kotlin.Short = 0.toShort() + public const final val stringField: kotlin.String = "0" + public const final val stringFieldNull: kotlin.String! + public final val uByteField: kotlin.UByte! + public final val uIntField: kotlin.UInt! + public final val uLongField: kotlin.ULong! + public final val uShortField: kotlin.UShort! +} diff --git a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/DiagnosticTestGenerated.java b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/DiagnosticTestGenerated.java index 17605b22d17..4f743107345 100644 --- a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/DiagnosticTestGenerated.java +++ b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/DiagnosticTestGenerated.java @@ -23705,6 +23705,12 @@ public class DiagnosticTestGenerated extends AbstractDiagnosticTest { runTest("compiler/testData/diagnostics/tests/modifiers/const/kt57802.kt"); } + @Test + @TestMetadata("noConstKt12248.kt") + public void testNoConstKt12248() throws Exception { + runTest("compiler/testData/diagnostics/tests/modifiers/const/noConstKt12248.kt"); + } + @Test @TestMetadata("stdlibConstFun.kt") public void testStdlibConstFun() throws Exception { diff --git a/compiler/tests-gen/org/jetbrains/kotlin/jvm/compiler/LoadJavaTestGenerated.java b/compiler/tests-gen/org/jetbrains/kotlin/jvm/compiler/LoadJavaTestGenerated.java index 5846f7219d1..06b1327225a 100644 --- a/compiler/tests-gen/org/jetbrains/kotlin/jvm/compiler/LoadJavaTestGenerated.java +++ b/compiler/tests-gen/org/jetbrains/kotlin/jvm/compiler/LoadJavaTestGenerated.java @@ -1596,6 +1596,11 @@ public class LoadJavaTestGenerated extends AbstractLoadJavaTest { runTest("compiler/testData/loadJava/compiledJava/static/StaticFinal.java"); } + @TestMetadata("StaticFinalConstTypes.java") + public void testStaticFinalConstTypes() throws Exception { + runTest("compiler/testData/loadJava/compiledJava/static/StaticFinalConstTypes.java"); + } + @TestMetadata("StaticMembersFromParentClass.java") public void testStaticMembersFromParentClass() throws Exception { runTest("compiler/testData/loadJava/compiledJava/static/StaticMembersFromParentClass.java"); diff --git a/compiler/tests-gen/org/jetbrains/kotlin/jvm/compiler/LoadJavaWithPsiClassReadingTestGenerated.java b/compiler/tests-gen/org/jetbrains/kotlin/jvm/compiler/LoadJavaWithPsiClassReadingTestGenerated.java index 1fc6f0b6ad0..cbd2d583b84 100644 --- a/compiler/tests-gen/org/jetbrains/kotlin/jvm/compiler/LoadJavaWithPsiClassReadingTestGenerated.java +++ b/compiler/tests-gen/org/jetbrains/kotlin/jvm/compiler/LoadJavaWithPsiClassReadingTestGenerated.java @@ -1594,6 +1594,11 @@ public class LoadJavaWithPsiClassReadingTestGenerated extends AbstractLoadJavaWi runTest("compiler/testData/loadJava/compiledJava/static/StaticFinal.java"); } + @TestMetadata("StaticFinalConstTypes.java") + public void testStaticFinalConstTypes() throws Exception { + runTest("compiler/testData/loadJava/compiledJava/static/StaticFinalConstTypes.java"); + } + @TestMetadata("StaticMembersFromParentClass.java") public void testStaticMembersFromParentClass() throws Exception { runTest("compiler/testData/loadJava/compiledJava/static/StaticMembersFromParentClass.java"); diff --git a/compiler/tests-gen/org/jetbrains/kotlin/jvm/compiler/ir/IrLoadJavaTestGenerated.java b/compiler/tests-gen/org/jetbrains/kotlin/jvm/compiler/ir/IrLoadJavaTestGenerated.java index 48b6ac782f3..cb9788329cb 100644 --- a/compiler/tests-gen/org/jetbrains/kotlin/jvm/compiler/ir/IrLoadJavaTestGenerated.java +++ b/compiler/tests-gen/org/jetbrains/kotlin/jvm/compiler/ir/IrLoadJavaTestGenerated.java @@ -1597,6 +1597,11 @@ public class IrLoadJavaTestGenerated extends AbstractIrLoadJavaTest { runTest("compiler/testData/loadJava/compiledJava/static/StaticFinal.java"); } + @TestMetadata("StaticFinalConstTypes.java") + public void testStaticFinalConstTypes() throws Exception { + runTest("compiler/testData/loadJava/compiledJava/static/StaticFinalConstTypes.java"); + } + @TestMetadata("StaticMembersFromParentClass.java") public void testStaticMembersFromParentClass() throws Exception { runTest("compiler/testData/loadJava/compiledJava/static/StaticMembersFromParentClass.java"); diff --git a/compiler/tests-gen/org/jetbrains/kotlin/jvm/compiler/javac/LoadJavaUsingJavacTestGenerated.java b/compiler/tests-gen/org/jetbrains/kotlin/jvm/compiler/javac/LoadJavaUsingJavacTestGenerated.java index b5265ec1300..f46d017e4fc 100644 --- a/compiler/tests-gen/org/jetbrains/kotlin/jvm/compiler/javac/LoadJavaUsingJavacTestGenerated.java +++ b/compiler/tests-gen/org/jetbrains/kotlin/jvm/compiler/javac/LoadJavaUsingJavacTestGenerated.java @@ -1596,6 +1596,11 @@ public class LoadJavaUsingJavacTestGenerated extends AbstractLoadJavaUsingJavacT runTest("compiler/testData/loadJava/compiledJava/static/StaticFinal.java"); } + @TestMetadata("StaticFinalConstTypes.java") + public void testStaticFinalConstTypes() throws Exception { + runTest("compiler/testData/loadJava/compiledJava/static/StaticFinalConstTypes.java"); + } + @TestMetadata("StaticMembersFromParentClass.java") public void testStaticMembersFromParentClass() throws Exception { runTest("compiler/testData/loadJava/compiledJava/static/StaticMembersFromParentClass.java"); diff --git a/core/descriptors.runtime/tests/org/jetbrains/kotlin/jvm/runtime/JvmRuntimeDescriptorLoaderTestGenerated.java b/core/descriptors.runtime/tests/org/jetbrains/kotlin/jvm/runtime/JvmRuntimeDescriptorLoaderTestGenerated.java index cb558742208..2d4b0233dc9 100644 --- a/core/descriptors.runtime/tests/org/jetbrains/kotlin/jvm/runtime/JvmRuntimeDescriptorLoaderTestGenerated.java +++ b/core/descriptors.runtime/tests/org/jetbrains/kotlin/jvm/runtime/JvmRuntimeDescriptorLoaderTestGenerated.java @@ -3846,6 +3846,11 @@ public class JvmRuntimeDescriptorLoaderTestGenerated extends AbstractJvmRuntimeD runTest("compiler/testData/loadJava/compiledJava/static/StaticFinal.java"); } + @TestMetadata("StaticFinalConstTypes.java") + public void testStaticFinalConstTypes() throws Exception { + runTest("compiler/testData/loadJava/compiledJava/static/StaticFinalConstTypes.java"); + } + @TestMetadata("StaticMembersFromParentClass.java") public void testStaticMembersFromParentClass() throws Exception { runTest("compiler/testData/loadJava/compiledJava/static/StaticMembersFromParentClass.java");