diff --git a/compiler/android-tests/tests/org/jetbrains/kotlin/android/tests/AndroidTestGenerator.kt b/compiler/android-tests/tests/org/jetbrains/kotlin/android/tests/AndroidTestGenerator.kt index a43c45fd4b0..53a1f17aea6 100644 --- a/compiler/android-tests/tests/org/jetbrains/kotlin/android/tests/AndroidTestGenerator.kt +++ b/compiler/android-tests/tests/org/jetbrains/kotlin/android/tests/AndroidTestGenerator.kt @@ -162,8 +162,13 @@ private fun getGeneratedClassName(file: File, text: String, newPackagePrefix: St for (annotation in FILE_NAME_ANNOTATIONS) { if (text.contains(annotation)) { val indexOf = text.indexOf(annotation) - val annotationParameter = text.substring(text.indexOf("(\"", indexOf) + 2, text.indexOf("\")", indexOf)) - return packageFqName.child(Name.identifier(annotationParameter)) + val startIndex = text.indexOf("(\"", indexOf) + val endIndex = text.indexOf("\")", indexOf) + // "start", "end" can be -1 in case when we use some const val in argument place + if (startIndex != -1 && endIndex != -1) { + val annotationParameter = text.substring(startIndex + 2, endIndex) + return packageFqName.child(Name.identifier(annotationParameter)) + } } } diff --git a/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/codegen/FirLightTreeBlackBoxCodegenTestGenerated.java b/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/codegen/FirLightTreeBlackBoxCodegenTestGenerated.java index 00a17a5ba61..6386848fbc7 100644 --- a/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/codegen/FirLightTreeBlackBoxCodegenTestGenerated.java +++ b/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/codegen/FirLightTreeBlackBoxCodegenTestGenerated.java @@ -28345,6 +28345,12 @@ public class FirLightTreeBlackBoxCodegenTestGenerated extends AbstractFirLightTr runTest("compiler/testData/codegen/box/involvesIrInterpreter/kt55108.kt"); } + @Test + @TestMetadata("kt55866.kt") + public void testKt55866() throws Exception { + runTest("compiler/testData/codegen/box/involvesIrInterpreter/kt55866.kt"); + } + @Test @TestMetadata("kt55912.kt") public void testKt55912() throws Exception { diff --git a/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/codegen/FirPsiBlackBoxCodegenTestGenerated.java b/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/codegen/FirPsiBlackBoxCodegenTestGenerated.java index daa1a47d8e4..c1338d0fc03 100644 --- a/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/codegen/FirPsiBlackBoxCodegenTestGenerated.java +++ b/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/codegen/FirPsiBlackBoxCodegenTestGenerated.java @@ -28345,6 +28345,12 @@ public class FirPsiBlackBoxCodegenTestGenerated extends AbstractFirPsiBlackBoxCo runTest("compiler/testData/codegen/box/involvesIrInterpreter/kt55108.kt"); } + @Test + @TestMetadata("kt55866.kt") + public void testKt55866() throws Exception { + runTest("compiler/testData/codegen/box/involvesIrInterpreter/kt55866.kt"); + } + @Test @TestMetadata("kt55912.kt") public void testKt55912() throws Exception { diff --git a/compiler/ir/ir.interpreter/src/org/jetbrains/kotlin/ir/interpreter/checker/IrConstDeclarationAnnotationTransformer.kt b/compiler/ir/ir.interpreter/src/org/jetbrains/kotlin/ir/interpreter/checker/IrConstDeclarationAnnotationTransformer.kt index 20c1d11e5c0..c6cb8fe1207 100644 --- a/compiler/ir/ir.interpreter/src/org/jetbrains/kotlin/ir/interpreter/checker/IrConstDeclarationAnnotationTransformer.kt +++ b/compiler/ir/ir.interpreter/src/org/jetbrains/kotlin/ir/interpreter/checker/IrConstDeclarationAnnotationTransformer.kt @@ -22,6 +22,11 @@ internal class IrConstDeclarationAnnotationTransformer( onError: (IrFile, IrElement, IrErrorExpression) -> Unit, suppressExceptions: Boolean, ) : IrConstAnnotationTransformer(interpreter, irFile, mode, evaluatedConstTracker, onWarning, onError, suppressExceptions) { + override fun visitFile(declaration: IrFile, data: Nothing?): IrFile { + transformAnnotations(declaration) + return super.visitFile(declaration, data) + } + override fun visitDeclaration(declaration: IrDeclarationBase, data: Nothing?): IrStatement { transformAnnotations(declaration) return super.visitDeclaration(declaration, data) diff --git a/compiler/ir/ir.interpreter/src/org/jetbrains/kotlin/ir/interpreter/checker/IrConstTransformer.kt b/compiler/ir/ir.interpreter/src/org/jetbrains/kotlin/ir/interpreter/checker/IrConstTransformer.kt index abdf38383ce..0f1fc8aa9cc 100644 --- a/compiler/ir/ir.interpreter/src/org/jetbrains/kotlin/ir/interpreter/checker/IrConstTransformer.kt +++ b/compiler/ir/ir.interpreter/src/org/jetbrains/kotlin/ir/interpreter/checker/IrConstTransformer.kt @@ -9,7 +9,7 @@ import org.jetbrains.kotlin.constant.ErrorValue import org.jetbrains.kotlin.constant.EvaluatedConstTracker import org.jetbrains.kotlin.ir.IrElement import org.jetbrains.kotlin.ir.declarations.IrFile -import org.jetbrains.kotlin.ir.declarations.name +import org.jetbrains.kotlin.ir.declarations.nameWithPackage import org.jetbrains.kotlin.ir.expressions.IrConst import org.jetbrains.kotlin.ir.expressions.IrErrorExpression import org.jetbrains.kotlin.ir.expressions.IrExpression @@ -19,7 +19,6 @@ import org.jetbrains.kotlin.ir.interpreter.IrInterpreterConfiguration import org.jetbrains.kotlin.ir.interpreter.toConstantValue import org.jetbrains.kotlin.ir.util.dump import org.jetbrains.kotlin.ir.visitors.IrElementTransformer -import org.jetbrains.kotlin.name.Name fun IrFile.transformConst( interpreter: IrInterpreter, @@ -99,7 +98,7 @@ internal abstract class IrConstTransformer( } evaluatedConstTracker?.save( - result.startOffset, result.endOffset, irFile.fqName.child(Name.identifier(irFile.name)).asString(), + result.startOffset, result.endOffset, irFile.nameWithPackage, constant = if (result is IrErrorExpression) ErrorValue.create(result.description) else (result as IrConst<*>).toConstantValue() ) diff --git a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/declarations/IrDeclarations.kt b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/declarations/IrDeclarations.kt index 3e212a8ce60..179545cf25a 100644 --- a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/declarations/IrDeclarations.kt +++ b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/declarations/IrDeclarations.kt @@ -12,6 +12,7 @@ import org.jetbrains.kotlin.descriptors.ValueParameterDescriptor import org.jetbrains.kotlin.ir.ObsoleteDescriptorBasedAPI import org.jetbrains.kotlin.ir.expressions.IrExpressionBody import org.jetbrains.kotlin.ir.types.IrSimpleType +import org.jetbrains.kotlin.name.Name import java.io.File fun D.copyAttributes(other: IrAttributeContainer?): D = apply { @@ -37,6 +38,7 @@ fun IrClass.addAll(members: List) { val IrFile.path: String get() = fileEntry.name val IrFile.name: String get() = File(path).name +val IrFile.nameWithPackage: String get() = fqName.child(Name.identifier(name)).asString() @ObsoleteDescriptorBasedAPI fun IrFunction.getIrValueParameter(parameter: ValueParameterDescriptor): IrValueParameter = diff --git a/compiler/testData/codegen/box/involvesIrInterpreter/kt55866.kt b/compiler/testData/codegen/box/involvesIrInterpreter/kt55866.kt new file mode 100644 index 00000000000..38d88601e0a --- /dev/null +++ b/compiler/testData/codegen/box/involvesIrInterpreter/kt55866.kt @@ -0,0 +1,11 @@ +// TARGET_BACKEND: JVM +// WITH_STDLIB + +@file:JvmName(TAG) +package root + +private const val TAG = "Tagged" + +class ConstParamFiller + +fun box(): String = "OK" diff --git a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/BlackBoxCodegenTestGenerated.java b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/BlackBoxCodegenTestGenerated.java index 79e35333019..dc6ade1de98 100644 --- a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/BlackBoxCodegenTestGenerated.java +++ b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/BlackBoxCodegenTestGenerated.java @@ -27211,6 +27211,12 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest { KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/involvesIrInterpreter"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JVM, true); } + @Test + @TestMetadata("kt55866.kt") + public void testKt55866() throws Exception { + runTest("compiler/testData/codegen/box/involvesIrInterpreter/kt55866.kt"); + } + @Test @TestMetadata("kt55912.kt") public void testKt55912() throws Exception { diff --git a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/IrBlackBoxCodegenTestGenerated.java b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/IrBlackBoxCodegenTestGenerated.java index f39dc7f7189..f14c33a9fe8 100644 --- a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/IrBlackBoxCodegenTestGenerated.java +++ b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/IrBlackBoxCodegenTestGenerated.java @@ -28345,6 +28345,12 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes runTest("compiler/testData/codegen/box/involvesIrInterpreter/kt55108.kt"); } + @Test + @TestMetadata("kt55866.kt") + public void testKt55866() throws Exception { + runTest("compiler/testData/codegen/box/involvesIrInterpreter/kt55866.kt"); + } + @Test @TestMetadata("kt55912.kt") public void testKt55912() throws Exception { diff --git a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/IrBlackBoxCodegenWithIrInlinerTestGenerated.java b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/IrBlackBoxCodegenWithIrInlinerTestGenerated.java index 02184fb65a8..ecd66b4b585 100644 --- a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/IrBlackBoxCodegenWithIrInlinerTestGenerated.java +++ b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/IrBlackBoxCodegenWithIrInlinerTestGenerated.java @@ -28345,6 +28345,12 @@ public class IrBlackBoxCodegenWithIrInlinerTestGenerated extends AbstractIrBlack runTest("compiler/testData/codegen/box/involvesIrInterpreter/kt55108.kt"); } + @Test + @TestMetadata("kt55866.kt") + public void testKt55866() throws Exception { + runTest("compiler/testData/codegen/box/involvesIrInterpreter/kt55866.kt"); + } + @Test @TestMetadata("kt55912.kt") public void testKt55912() throws Exception { diff --git a/compiler/tests-common-new/tests/org/jetbrains/kotlin/test/backend/handlers/IrInterpreterDumpHandler.kt b/compiler/tests-common-new/tests/org/jetbrains/kotlin/test/backend/handlers/IrInterpreterDumpHandler.kt index 0571ca3863b..eec128f1347 100644 --- a/compiler/tests-common-new/tests/org/jetbrains/kotlin/test/backend/handlers/IrInterpreterDumpHandler.kt +++ b/compiler/tests-common-new/tests/org/jetbrains/kotlin/test/backend/handlers/IrInterpreterDumpHandler.kt @@ -11,7 +11,7 @@ import org.jetbrains.kotlin.config.CommonConfigurationKeys import org.jetbrains.kotlin.constant.ErrorValue import org.jetbrains.kotlin.constant.EvaluatedConstTracker import org.jetbrains.kotlin.ir.declarations.IrFile -import org.jetbrains.kotlin.ir.declarations.name +import org.jetbrains.kotlin.ir.declarations.nameWithPackage import org.jetbrains.kotlin.test.TargetBackend import org.jetbrains.kotlin.test.directives.CodegenTestDirectives.IGNORE_BACKEND_K2 import org.jetbrains.kotlin.test.model.* @@ -51,7 +51,7 @@ interface IrInterpreterDumpHandler { private fun EvaluatedConstTracker.processFile(testFile: TestFile, irFile: IrFile) { val rangesThatAreNotSupposedToBeRendered = testFile.extractRangesWithoutRender() - this.load(irFile.name)?.forEach { (pair, constantValue) -> + this.load(irFile.nameWithPackage)?.forEach { (pair, constantValue) -> val (start, end) = pair if (rangesThatAreNotSupposedToBeRendered.any { start >= it.first && start <= it.second }) return@forEach diff --git a/compiler/tests-gen/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java b/compiler/tests-gen/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java index 44ec3bb88d8..03fcc3c4f59 100644 --- a/compiler/tests-gen/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java +++ b/compiler/tests-gen/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java @@ -22962,6 +22962,11 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/involvesIrInterpreter"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JVM, true); } + @TestMetadata("kt55866.kt") + public void testKt55866() throws Exception { + runTest("compiler/testData/codegen/box/involvesIrInterpreter/kt55866.kt"); + } + @TestMetadata("kt55912.kt") public void testKt55912() throws Exception { runTest("compiler/testData/codegen/box/involvesIrInterpreter/kt55912.kt");