diff --git a/compiler/backend/src/org/jetbrains/jet/codegen/FunctionCodegen.java b/compiler/backend/src/org/jetbrains/jet/codegen/FunctionCodegen.java index 052cdc80ac7..7c8a8fa8034 100644 --- a/compiler/backend/src/org/jetbrains/jet/codegen/FunctionCodegen.java +++ b/compiler/backend/src/org/jetbrains/jet/codegen/FunctionCodegen.java @@ -562,14 +562,21 @@ public class FunctionCodegen extends ParentCodegenAwareImpl { if (!isStatic && !isConstructor) { descriptor = descriptor.replace("(", "(" + ownerType.getDescriptor()); } + + Method defaultMethod = new Method(isConstructor ? "" : jvmSignature.getName() + JvmAbi.DEFAULT_PARAMS_IMPL_SUFFIX, descriptor); MethodVisitor mv = v.newMethod(null, flags | (isConstructor ? 0 : ACC_STATIC), - isConstructor ? "" : jvmSignature.getName() + JvmAbi.DEFAULT_PARAMS_IMPL_SUFFIX, - descriptor, null, + defaultMethod.getName(), + defaultMethod.getDescriptor(), null, getThrownExceptions(functionDescriptor, typeMapper)); if (state.getClassBuilderMode() == ClassBuilderMode.FULL) { - generateDefaultImpl(owner, signature, functionDescriptor, isStatic, mv, loadStrategy); - + if (this.owner instanceof PackageFacadeContext) { + mv.visitCode(); + generateStaticDelegateMethodBody(mv, defaultMethod, (PackageFacadeContext) this.owner); + endVisit(mv, "default method delegation", callableDescriptorToDeclaration(state.getBindingContext(), functionDescriptor)); + } else { + generateDefaultImpl(owner, signature, functionDescriptor, isStatic, mv, loadStrategy); + } } } diff --git a/compiler/testData/codegen/bytecodeText/defaultDelegation.kt b/compiler/testData/codegen/bytecodeText/defaultDelegation.kt new file mode 100644 index 00000000000..786304e02ba --- /dev/null +++ b/compiler/testData/codegen/bytecodeText/defaultDelegation.kt @@ -0,0 +1,8 @@ +package foo + +fun simpleFoo(s: Int = 111) { + +} + +// 1 BIPUSH 111 +// 1 INVOKESTATIC foo/FooPackage-.*\.simpleFoo\$default \(II\)V \ No newline at end of file diff --git a/compiler/tests/org/jetbrains/jet/codegen/BytecodeTextTestGenerated.java b/compiler/tests/org/jetbrains/jet/codegen/BytecodeTextTestGenerated.java index 115cf10aa91..a84f13e8581 100644 --- a/compiler/tests/org/jetbrains/jet/codegen/BytecodeTextTestGenerated.java +++ b/compiler/tests/org/jetbrains/jet/codegen/BytecodeTextTestGenerated.java @@ -72,6 +72,11 @@ public class BytecodeTextTestGenerated extends AbstractBytecodeTextTest { doTest("compiler/testData/codegen/bytecodeText/constClosureOptimization.kt"); } + @TestMetadata("defaultDelegation.kt") + public void testDefaultDelegation() throws Exception { + doTest("compiler/testData/codegen/bytecodeText/defaultDelegation.kt"); + } + @TestMetadata("intConstantNotNull.kt") public void testIntConstantNotNull() throws Exception { doTest("compiler/testData/codegen/bytecodeText/intConstantNotNull.kt");