diff --git a/compiler/testData/codegen/box/ir/kt29833.kt b/compiler/testData/codegen/box/ir/kt29833.kt new file mode 100644 index 00000000000..96e35070f9a --- /dev/null +++ b/compiler/testData/codegen/box/ir/kt29833.kt @@ -0,0 +1,19 @@ +// TARGET_BACKEND: JVM +// FILE: Definitions.kt +import interop.* + +object Definitions { + const val KT_CONSTANT = Interface.CONSTANT + + val ktValue = Interface.CONSTANT +} + +fun box(): String = + Definitions.ktValue + +// FILE: interop/Interface.java +package interop; + +public class Interface { + public static final String CONSTANT = "OK"; +} diff --git a/compiler/testData/ir/irText/declarations/kt29833.kt b/compiler/testData/ir/irText/declarations/kt29833.kt new file mode 100644 index 00000000000..aa59cabbc5a --- /dev/null +++ b/compiler/testData/ir/irText/declarations/kt29833.kt @@ -0,0 +1,17 @@ +// FILE: Definitions.kt +// IR_FILE: kt29833.txt +package interop + +object Definitions { + const val KT_CONSTANT = Interface.CONSTANT + + val ktValue = Interface.CONSTANT +} + +// FILE: interop/Interface.java +package interop; + +class Interface { + public static final String CONSTANT = "constant"; + public CharSequence chars; +} diff --git a/compiler/testData/ir/irText/declarations/kt29833.txt b/compiler/testData/ir/irText/declarations/kt29833.txt new file mode 100644 index 00000000000..cf9ab83e565 --- /dev/null +++ b/compiler/testData/ir/irText/declarations/kt29833.txt @@ -0,0 +1,42 @@ +FILE fqName:interop fileName:/Definitions.kt + CLASS OBJECT name:Definitions modality:FINAL visibility:public flags: superTypes:[kotlin.Any] + $this: VALUE_PARAMETER INSTANCE_RECEIVER name: type:interop.Definitions flags: + CONSTRUCTOR visibility:private <> () returnType:interop.Definitions flags:primary + BLOCK_BODY + DELEGATING_CONSTRUCTOR_CALL 'constructor Any()' + INSTANCE_INITIALIZER_CALL classDescriptor='Definitions' + PROPERTY name:KT_CONSTANT visibility:public modality:FINAL flags:const,val + FIELD PROPERTY_BACKING_FIELD name:KT_CONSTANT type:kotlin.String visibility:public flags:final + EXPRESSION_BODY + CONST String type=kotlin.String value="constant" + FUN DEFAULT_PROPERTY_ACCESSOR name: visibility:public modality:FINAL <> ($this:interop.Definitions) returnType:kotlin.String flags: + correspondingProperty: PROPERTY name:KT_CONSTANT visibility:public modality:FINAL flags:const,val + $this: VALUE_PARAMETER name: type:interop.Definitions flags: + BLOCK_BODY + RETURN type=kotlin.Nothing from='(): String' + GET_FIELD 'KT_CONSTANT: String' type=kotlin.String origin=null + receiver: GET_VAR 'this@Definitions: Definitions' type=interop.Definitions origin=null + PROPERTY name:ktValue visibility:public modality:FINAL flags:val + FIELD PROPERTY_BACKING_FIELD name:ktValue type:kotlin.String visibility:public flags:final + EXPRESSION_BODY + GET_FIELD 'CONSTANT: String' type=kotlin.String origin=GET_PROPERTY + FUN DEFAULT_PROPERTY_ACCESSOR name: visibility:public modality:FINAL <> ($this:interop.Definitions) returnType:kotlin.String flags: + correspondingProperty: PROPERTY name:ktValue visibility:public modality:FINAL flags:val + $this: VALUE_PARAMETER name: type:interop.Definitions flags: + BLOCK_BODY + RETURN type=kotlin.Nothing from='(): String' + GET_FIELD 'ktValue: String' type=kotlin.String origin=null + receiver: GET_VAR 'this@Definitions: Definitions' type=interop.Definitions origin=null + FUN FAKE_OVERRIDE name:equals visibility:public modality:OPEN <> ($this:kotlin.Any, other:kotlin.Any?) returnType:kotlin.Boolean flags: + overridden: + FUN IR_EXTERNAL_DECLARATION_STUB name:equals visibility:public modality:OPEN <> ($this:kotlin.Any, other:kotlin.Any?) returnType:kotlin.Boolean flags: + $this: VALUE_PARAMETER name: type:kotlin.Any flags: + VALUE_PARAMETER name:other index:0 type:kotlin.Any? flags: + FUN FAKE_OVERRIDE name:hashCode visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:kotlin.Int flags: + overridden: + FUN IR_EXTERNAL_DECLARATION_STUB name:hashCode visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:kotlin.Int flags: + $this: VALUE_PARAMETER name: type:kotlin.Any flags: + FUN FAKE_OVERRIDE name:toString visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:kotlin.String flags: + overridden: + FUN IR_EXTERNAL_DECLARATION_STUB name:toString visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:kotlin.String flags: + $this: VALUE_PARAMETER name: type:kotlin.Any flags: diff --git a/compiler/tests-common/tests/org/jetbrains/kotlin/ir/AbstractIrTextTestCase.kt b/compiler/tests-common/tests/org/jetbrains/kotlin/ir/AbstractIrTextTestCase.kt index 6ca1a84f2b8..d3f9c0dc485 100644 --- a/compiler/tests-common/tests/org/jetbrains/kotlin/ir/AbstractIrTextTestCase.kt +++ b/compiler/tests-common/tests/org/jetbrains/kotlin/ir/AbstractIrTextTestCase.kt @@ -236,6 +236,15 @@ abstract class AbstractIrTextTestCase : AbstractIrGeneratorTestCase() { private fun IrSymbol.checkBinding(kind: String, irElement: IrElement) { if (!isBound) { error("${javaClass.simpleName} $descriptor is unbound @$kind ${irElement.render()}") + } else { + val irDeclaration = owner as? IrDeclaration + if (irDeclaration != null) { + try { + irDeclaration.parent + } catch (e: Throwable) { + error("Referenced declaration has no parent: ${irDeclaration.render()}") + } + } } val otherSymbol = symbolForDeclaration.getOrPut(owner) { this } diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java index 2dc8b7a7bbf..19b0e5b1423 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java @@ -13432,6 +13432,11 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest { runTest("compiler/testData/codegen/box/ir/kt25405.kt"); } + @TestMetadata("kt29833.kt") + public void testKt29833() throws Exception { + runTest("compiler/testData/codegen/box/ir/kt29833.kt"); + } + @TestMetadata("objectClass.kt") public void testObjectClass() throws Exception { runTest("compiler/testData/codegen/box/ir/objectClass.kt"); diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java index 707694396cf..679b5d35f67 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java @@ -13432,6 +13432,11 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes runTest("compiler/testData/codegen/box/ir/kt25405.kt"); } + @TestMetadata("kt29833.kt") + public void testKt29833() throws Exception { + runTest("compiler/testData/codegen/box/ir/kt29833.kt"); + } + @TestMetadata("objectClass.kt") public void testObjectClass() throws Exception { runTest("compiler/testData/codegen/box/ir/objectClass.kt"); diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java index 3cf54d70e8c..11b5cc9eefd 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java @@ -13437,6 +13437,11 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes runTest("compiler/testData/codegen/box/ir/kt25405.kt"); } + @TestMetadata("kt29833.kt") + public void testKt29833() throws Exception { + runTest("compiler/testData/codegen/box/ir/kt29833.kt"); + } + @TestMetadata("objectClass.kt") public void testObjectClass() throws Exception { runTest("compiler/testData/codegen/box/ir/objectClass.kt"); diff --git a/compiler/tests/org/jetbrains/kotlin/ir/IrTextTestCaseGenerated.java b/compiler/tests/org/jetbrains/kotlin/ir/IrTextTestCaseGenerated.java index d01a4ec89eb..4756ea4080f 100644 --- a/compiler/tests/org/jetbrains/kotlin/ir/IrTextTestCaseGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/ir/IrTextTestCaseGenerated.java @@ -274,6 +274,11 @@ public class IrTextTestCaseGenerated extends AbstractIrTextTestCase { runTest("compiler/testData/ir/irText/declarations/kt27005.kt"); } + @TestMetadata("kt29833.kt") + public void testKt29833() throws Exception { + runTest("compiler/testData/ir/irText/declarations/kt29833.kt"); + } + @TestMetadata("localClassWithOverrides.kt") public void testLocalClassWithOverrides() throws Exception { runTest("compiler/testData/ir/irText/declarations/localClassWithOverrides.kt");