From 8e45bb7657185dd441b509d2e1d75fc451d25554 Mon Sep 17 00:00:00 2001 From: "Natalia.Ukhorskaya" Date: Mon, 5 Aug 2013 16:20:25 +0400 Subject: [PATCH] Fix wrong generated class name invoking inner objects from another module --- .../jet/codegen/binding/CodegenBinding.java | 8 +++----- .../InnerClass.A.kt | 7 +++++++ .../InnerClass.B.kt | 6 ++++++ .../compileKotlinAgainstKotlin/InnerEnum.A.kt | 7 +++++++ .../compileKotlinAgainstKotlin/InnerEnum.B.kt | 6 ++++++ .../InnerInnerClass.A.kt | 9 +++++++++ .../InnerInnerClass.B.kt | 6 ++++++ .../InnerObject.A.kt | 7 +++++++ .../InnerObject.B.kt | 6 ++++++ ...mpileKotlinAgainstKotlinTestGenerated.java | 20 +++++++++++++++++++ 10 files changed, 77 insertions(+), 5 deletions(-) create mode 100644 compiler/testData/compileKotlinAgainstKotlin/InnerClass.A.kt create mode 100644 compiler/testData/compileKotlinAgainstKotlin/InnerClass.B.kt create mode 100644 compiler/testData/compileKotlinAgainstKotlin/InnerEnum.A.kt create mode 100644 compiler/testData/compileKotlinAgainstKotlin/InnerEnum.B.kt create mode 100644 compiler/testData/compileKotlinAgainstKotlin/InnerInnerClass.A.kt create mode 100644 compiler/testData/compileKotlinAgainstKotlin/InnerInnerClass.B.kt create mode 100644 compiler/testData/compileKotlinAgainstKotlin/InnerObject.A.kt create mode 100644 compiler/testData/compileKotlinAgainstKotlin/InnerObject.B.kt diff --git a/compiler/backend/src/org/jetbrains/jet/codegen/binding/CodegenBinding.java b/compiler/backend/src/org/jetbrains/jet/codegen/binding/CodegenBinding.java index 20b2f66c69a..c80c84b8346 100644 --- a/compiler/backend/src/org/jetbrains/jet/codegen/binding/CodegenBinding.java +++ b/compiler/backend/src/org/jetbrains/jet/codegen/binding/CodegenBinding.java @@ -362,16 +362,14 @@ public class CodegenBinding { if (containingKlass.getKind() == ClassKind.ENUM_CLASS) { return getJvmInternalName(bindingTrace, containingKlass).getInternalName(); } + else if (klass.getKind() == ClassKind.OBJECT) { + return getJvmInternalName(bindingTrace, containingKlass).getInternalName() + "$" + klass.getName(); + } else { return getJvmInternalName(bindingTrace, containingKlass).getInternalName() + JvmAbi.CLASS_OBJECT_SUFFIX; } } } - - JvmClassName name = bindingTrace.getBindingContext().get(FQN, descriptor); - if (name != null) { - return name.getInternalName(); - } } DeclarationDescriptor container = descriptor.getContainingDeclaration(); diff --git a/compiler/testData/compileKotlinAgainstKotlin/InnerClass.A.kt b/compiler/testData/compileKotlinAgainstKotlin/InnerClass.A.kt new file mode 100644 index 00000000000..6a3ed2aabe0 --- /dev/null +++ b/compiler/testData/compileKotlinAgainstKotlin/InnerClass.A.kt @@ -0,0 +1,7 @@ +package aaa + +class A { + class O { + val s = "OK" + } +} diff --git a/compiler/testData/compileKotlinAgainstKotlin/InnerClass.B.kt b/compiler/testData/compileKotlinAgainstKotlin/InnerClass.B.kt new file mode 100644 index 00000000000..b8a6a820084 --- /dev/null +++ b/compiler/testData/compileKotlinAgainstKotlin/InnerClass.B.kt @@ -0,0 +1,6 @@ +fun main(args: Array) { + val str = aaa.A.O().s + if (str != "OK") { + throw Exception() + } +} diff --git a/compiler/testData/compileKotlinAgainstKotlin/InnerEnum.A.kt b/compiler/testData/compileKotlinAgainstKotlin/InnerEnum.A.kt new file mode 100644 index 00000000000..5a78c80b05d --- /dev/null +++ b/compiler/testData/compileKotlinAgainstKotlin/InnerEnum.A.kt @@ -0,0 +1,7 @@ +package aaa + +class A { + enum class E { + A + } +} diff --git a/compiler/testData/compileKotlinAgainstKotlin/InnerEnum.B.kt b/compiler/testData/compileKotlinAgainstKotlin/InnerEnum.B.kt new file mode 100644 index 00000000000..ad3eb7e8928 --- /dev/null +++ b/compiler/testData/compileKotlinAgainstKotlin/InnerEnum.B.kt @@ -0,0 +1,6 @@ +fun main(args: Array) { + val str = aaa.A().E.A + if (str.toString() != "A") { + throw Exception() + } +} diff --git a/compiler/testData/compileKotlinAgainstKotlin/InnerInnerClass.A.kt b/compiler/testData/compileKotlinAgainstKotlin/InnerInnerClass.A.kt new file mode 100644 index 00000000000..ed2026e7465 --- /dev/null +++ b/compiler/testData/compileKotlinAgainstKotlin/InnerInnerClass.A.kt @@ -0,0 +1,9 @@ +package aaa + +class A { + class B { + class O { + val s = "OK" + } + } +} diff --git a/compiler/testData/compileKotlinAgainstKotlin/InnerInnerClass.B.kt b/compiler/testData/compileKotlinAgainstKotlin/InnerInnerClass.B.kt new file mode 100644 index 00000000000..47d981ab079 --- /dev/null +++ b/compiler/testData/compileKotlinAgainstKotlin/InnerInnerClass.B.kt @@ -0,0 +1,6 @@ +fun main(args: Array) { + val str = aaa.A.B.O().s + if (str != "OK") { + throw Exception() + } +} diff --git a/compiler/testData/compileKotlinAgainstKotlin/InnerObject.A.kt b/compiler/testData/compileKotlinAgainstKotlin/InnerObject.A.kt new file mode 100644 index 00000000000..d80cbb09e23 --- /dev/null +++ b/compiler/testData/compileKotlinAgainstKotlin/InnerObject.A.kt @@ -0,0 +1,7 @@ +package aaa + +class A { + object O { + val s = "OK" + } +} diff --git a/compiler/testData/compileKotlinAgainstKotlin/InnerObject.B.kt b/compiler/testData/compileKotlinAgainstKotlin/InnerObject.B.kt new file mode 100644 index 00000000000..70f3f5209be --- /dev/null +++ b/compiler/testData/compileKotlinAgainstKotlin/InnerObject.B.kt @@ -0,0 +1,6 @@ +fun main(args: Array) { + val str = aaa.A().O.s + if (str != "OK") { + throw Exception() + } +} diff --git a/compiler/tests/org/jetbrains/jet/jvm/compiler/CompileKotlinAgainstKotlinTestGenerated.java b/compiler/tests/org/jetbrains/jet/jvm/compiler/CompileKotlinAgainstKotlinTestGenerated.java index 85c06266d3f..4e750ab007f 100644 --- a/compiler/tests/org/jetbrains/jet/jvm/compiler/CompileKotlinAgainstKotlinTestGenerated.java +++ b/compiler/tests/org/jetbrains/jet/jvm/compiler/CompileKotlinAgainstKotlinTestGenerated.java @@ -56,6 +56,26 @@ public class CompileKotlinAgainstKotlinTestGenerated extends AbstractCompileKotl doTest("compiler/testData/compileKotlinAgainstKotlin/ImportObject.A.kt"); } + @TestMetadata("InnerClass.A.kt") + public void testInnerClass() throws Exception { + doTest("compiler/testData/compileKotlinAgainstKotlin/InnerClass.A.kt"); + } + + @TestMetadata("InnerEnum.A.kt") + public void testInnerEnum() throws Exception { + doTest("compiler/testData/compileKotlinAgainstKotlin/InnerEnum.A.kt"); + } + + @TestMetadata("InnerInnerClass.A.kt") + public void testInnerInnerClass() throws Exception { + doTest("compiler/testData/compileKotlinAgainstKotlin/InnerInnerClass.A.kt"); + } + + @TestMetadata("InnerObject.A.kt") + public void testInnerObject() throws Exception { + doTest("compiler/testData/compileKotlinAgainstKotlin/InnerObject.A.kt"); + } + @TestMetadata("Simple.A.kt") public void testSimple() throws Exception { doTest("compiler/testData/compileKotlinAgainstKotlin/Simple.A.kt");