From cdceaec79f2783f139d427241dc68d5ccdfb83f5 Mon Sep 17 00:00:00 2001 From: Alexander Udalov Date: Fri, 18 Apr 2014 17:18:51 +0400 Subject: [PATCH] Fix unjustified descriptorToDeclaration in bridge codegen Delegated and synthesized members don't usually have a declaration as well as fake overrides --- .../jetbrains/jet/codegen/FunctionCodegen.java | 5 ++--- .../delegationAndInheritanceFromJava.java | 7 +++++++ .../delegationAndInheritanceFromJava.kt | 6 ++++++ .../BlackBoxWithJavaCodegenTestGenerated.java | 16 +++++++++++++++- 4 files changed, 30 insertions(+), 4 deletions(-) create mode 100644 compiler/testData/codegen/boxWithJava/delegation/delegationAndInheritanceFromJava.java create mode 100644 compiler/testData/codegen/boxWithJava/delegation/delegationAndInheritanceFromJava.kt diff --git a/compiler/backend/src/org/jetbrains/jet/codegen/FunctionCodegen.java b/compiler/backend/src/org/jetbrains/jet/codegen/FunctionCodegen.java index 94487331fb9..51e2339e260 100644 --- a/compiler/backend/src/org/jetbrains/jet/codegen/FunctionCodegen.java +++ b/compiler/backend/src/org/jetbrains/jet/codegen/FunctionCodegen.java @@ -66,6 +66,7 @@ import static org.jetbrains.jet.codegen.AsmUtil.*; import static org.jetbrains.jet.codegen.JvmSerializationBindings.*; import static org.jetbrains.jet.codegen.binding.CodegenBinding.asmTypeForAnonymousClass; import static org.jetbrains.jet.codegen.binding.CodegenBinding.isLocalNamedFun; +import static org.jetbrains.jet.lang.descriptors.CallableMemberDescriptor.Kind.DECLARATION; import static org.jetbrains.jet.lang.resolve.BindingContextUtils.callableDescriptorToDeclaration; import static org.jetbrains.jet.lang.resolve.BindingContextUtils.descriptorToDeclaration; import static org.jetbrains.jet.lang.resolve.DescriptorUtils.isFunctionLiteral; @@ -440,9 +441,7 @@ public class FunctionCodegen extends ParentCodegenAwareImpl { ); if (!bridgesToGenerate.isEmpty()) { - PsiElement origin = descriptor.getKind().isReal() - ? callableDescriptorToDeclaration(bindingContext, descriptor) - : null; + PsiElement origin = descriptor.getKind() == DECLARATION ? callableDescriptorToDeclaration(bindingContext, descriptor) : null; for (Bridge bridge : bridgesToGenerate) { generateBridge(origin, bridge.getFrom(), bridge.getTo()); } diff --git a/compiler/testData/codegen/boxWithJava/delegation/delegationAndInheritanceFromJava.java b/compiler/testData/codegen/boxWithJava/delegation/delegationAndInheritanceFromJava.java new file mode 100644 index 00000000000..ddb9ff115d0 --- /dev/null +++ b/compiler/testData/codegen/boxWithJava/delegation/delegationAndInheritanceFromJava.java @@ -0,0 +1,7 @@ +import java.util.Set; + +public class delegationAndInheritanceFromJava { + public interface A extends Set {} + + public interface B extends Set {} +} diff --git a/compiler/testData/codegen/boxWithJava/delegation/delegationAndInheritanceFromJava.kt b/compiler/testData/codegen/boxWithJava/delegation/delegationAndInheritanceFromJava.kt new file mode 100644 index 00000000000..6692a78a01d --- /dev/null +++ b/compiler/testData/codegen/boxWithJava/delegation/delegationAndInheritanceFromJava.kt @@ -0,0 +1,6 @@ +import delegationAndInheritanceFromJava.* +import java.util.HashSet + +class Impl(b: B): A, B by b + +fun box() = "OK" diff --git a/compiler/tests/org/jetbrains/jet/codegen/generated/BlackBoxWithJavaCodegenTestGenerated.java b/compiler/tests/org/jetbrains/jet/codegen/generated/BlackBoxWithJavaCodegenTestGenerated.java index 8efdecd5e2c..dbb9532a668 100644 --- a/compiler/tests/org/jetbrains/jet/codegen/generated/BlackBoxWithJavaCodegenTestGenerated.java +++ b/compiler/tests/org/jetbrains/jet/codegen/generated/BlackBoxWithJavaCodegenTestGenerated.java @@ -31,7 +31,7 @@ import org.jetbrains.jet.codegen.generated.AbstractBlackBoxCodegenTest; /** This class is generated by {@link org.jetbrains.jet.generators.tests.TestsPackage}. DO NOT MODIFY MANUALLY */ @SuppressWarnings("all") @TestMetadata("compiler/testData/codegen/boxWithJava") -@InnerTestClasses({BlackBoxWithJavaCodegenTestGenerated.Annotations.class, BlackBoxWithJavaCodegenTestGenerated.CallableReference.class, BlackBoxWithJavaCodegenTestGenerated.Constructor.class, BlackBoxWithJavaCodegenTestGenerated.Enum.class, BlackBoxWithJavaCodegenTestGenerated.Functions.class, BlackBoxWithJavaCodegenTestGenerated.InnerClass.class, BlackBoxWithJavaCodegenTestGenerated.Property.class, BlackBoxWithJavaCodegenTestGenerated.Sam.class, BlackBoxWithJavaCodegenTestGenerated.StaticFun.class, BlackBoxWithJavaCodegenTestGenerated.Visibility.class}) +@InnerTestClasses({BlackBoxWithJavaCodegenTestGenerated.Annotations.class, BlackBoxWithJavaCodegenTestGenerated.CallableReference.class, BlackBoxWithJavaCodegenTestGenerated.Constructor.class, BlackBoxWithJavaCodegenTestGenerated.Delegation.class, BlackBoxWithJavaCodegenTestGenerated.Enum.class, BlackBoxWithJavaCodegenTestGenerated.Functions.class, BlackBoxWithJavaCodegenTestGenerated.InnerClass.class, BlackBoxWithJavaCodegenTestGenerated.Property.class, BlackBoxWithJavaCodegenTestGenerated.Sam.class, BlackBoxWithJavaCodegenTestGenerated.StaticFun.class, BlackBoxWithJavaCodegenTestGenerated.Visibility.class}) public class BlackBoxWithJavaCodegenTestGenerated extends AbstractBlackBoxCodegenTest { public void testAllFilesPresentInBoxWithJava() throws Exception { JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), "org.jetbrains.jet.generators.tests.TestsPackage", new File("compiler/testData/codegen/boxWithJava"), Pattern.compile("^(.+)\\.kt$"), true); @@ -101,6 +101,19 @@ public class BlackBoxWithJavaCodegenTestGenerated extends AbstractBlackBoxCodege } + @TestMetadata("compiler/testData/codegen/boxWithJava/delegation") + public static class Delegation extends AbstractBlackBoxCodegenTest { + public void testAllFilesPresentInDelegation() throws Exception { + JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), "org.jetbrains.jet.generators.tests.TestsPackage", new File("compiler/testData/codegen/boxWithJava/delegation"), Pattern.compile("^(.+)\\.kt$"), true); + } + + @TestMetadata("delegationAndInheritanceFromJava.kt") + public void testDelegationAndInheritanceFromJava() throws Exception { + doTestWithJava("compiler/testData/codegen/boxWithJava/delegation/delegationAndInheritanceFromJava.kt"); + } + + } + @TestMetadata("compiler/testData/codegen/boxWithJava/enum") public static class Enum extends AbstractBlackBoxCodegenTest { public void testAllFilesPresentInEnum() throws Exception { @@ -566,6 +579,7 @@ public class BlackBoxWithJavaCodegenTestGenerated extends AbstractBlackBoxCodege suite.addTestSuite(Annotations.class); suite.addTestSuite(CallableReference.class); suite.addTestSuite(Constructor.class); + suite.addTestSuite(Delegation.class); suite.addTestSuite(Enum.class); suite.addTestSuite(Functions.class); suite.addTestSuite(InnerClass.class);