diff --git a/compiler/backend/src/org/jetbrains/jet/codegen/FunctionCodegen.java b/compiler/backend/src/org/jetbrains/jet/codegen/FunctionCodegen.java index c4c7640f770..8f9af00ca19 100644 --- a/compiler/backend/src/org/jetbrains/jet/codegen/FunctionCodegen.java +++ b/compiler/backend/src/org/jetbrains/jet/codegen/FunctionCodegen.java @@ -619,8 +619,8 @@ public class FunctionCodegen extends ParentCodegenAware { CallGenerator generator = codegen.getOrCreateCallGenerator(functionDescriptor, function); InstructionAdapter iv = new InstructionAdapter(mv); - loadExplicitArgumentsOnStack(iv, OBJECT_TYPE, isStatic, signature); - generator.putHiddenParams(); + + loadExplicitArgumentsOnStack(iv, OBJECT_TYPE, isStatic, signature, generator); List mappedParameters = signature.getValueParameters(); int capturedArgumentsCount = 0; @@ -698,18 +698,19 @@ public class FunctionCodegen extends ParentCodegenAware { @NotNull InstructionAdapter iv, @NotNull Type ownerType, boolean isStatic, - @NotNull JvmMethodSignature signature + @NotNull JvmMethodSignature signature, + @NotNull CallGenerator callGenerator ) { int var = 0; if (!isStatic) { - iv.load(var, ownerType); + callGenerator.putValueIfNeeded(null, ownerType, StackValue.local(var, ownerType)); var += ownerType.getSize(); } for (JvmMethodParameterSignature parameterSignature : signature.getValueParameters()) { if (parameterSignature.getKind() != JvmMethodParameterKind.VALUE) { Type type = parameterSignature.getAsmType(); - iv.load(var, type); + callGenerator.putValueIfNeeded(null, type, StackValue.local(var, type)); var += type.getSize(); } } diff --git a/compiler/backend/src/org/jetbrains/jet/codegen/inline/InlineCodegen.java b/compiler/backend/src/org/jetbrains/jet/codegen/inline/InlineCodegen.java index 0183c738e5b..6f4a93234cf 100644 --- a/compiler/backend/src/org/jetbrains/jet/codegen/inline/InlineCodegen.java +++ b/compiler/backend/src/org/jetbrains/jet/codegen/inline/InlineCodegen.java @@ -183,7 +183,7 @@ public class InlineCodegen implements CallGenerator { MethodContext methodContext = context.getParentContext().intoFunction(functionDescriptor); MemberCodegen parentCodegen = codegen.getParentCodegen(); if (callDefault) { - boolean isStatic = isStatic(codegen.getContext().getContextKind()); + boolean isStatic = isStatic(context.getContextKind()); FunctionCodegen.generateDefaultImplBody( methodContext, jvmSignature, functionDescriptor, isStatic, maxCalcAdapter, DefaultParameterValueLoader.DEFAULT, (JetNamedFunction) element, parentCodegen, state diff --git a/compiler/testData/codegen/boxInline/defaultValues/defaultInExtension.1.kt b/compiler/testData/codegen/boxInline/defaultValues/defaultInExtension.1.kt new file mode 100644 index 00000000000..501cd8b71ce --- /dev/null +++ b/compiler/testData/codegen/boxInline/defaultValues/defaultInExtension.1.kt @@ -0,0 +1,35 @@ +import test.* + +fun testExtensionInClass() : String { + + var res = with(Z(1)) { "1".run("OK") } + if (res != "1OK") return "failed in class 1: $res" + + res = with(Z(1)) { "1".run() } + if (res != "1null") return "failed in class 2: $res" + + res = with(Z(2)) { "3".run("OK", {(a, b) -> a + b + value }, 1) } + if (res != "OK123") return "failed in class 3: $res" + + res = with(Z(3)) { "4".run(lambda = {(a, b) -> a + b + value }) } + if (res != "034") return "failed in class 4: $res" + + return "OK" +} + +fun box(): String { + + var res = "1".run("OK") + if (res != "1OK") return "failed 1: $res" + + res = "1".run() + if (res != "1null") return "failed 2: $res" + + res = "3".run("OK", {(a, b) -> a + b}, 1) + if (res != "OK13") return "failed 3: $res" + + res = "4".run(lambda = {(a, b) -> a + b}) + if (res != "04") return "failed 4: $res" + + return testExtensionInClass() +} diff --git a/compiler/testData/codegen/boxInline/defaultValues/defaultInExtension.2.kt b/compiler/testData/codegen/boxInline/defaultValues/defaultInExtension.2.kt new file mode 100644 index 00000000000..e2255174276 --- /dev/null +++ b/compiler/testData/codegen/boxInline/defaultValues/defaultInExtension.2.kt @@ -0,0 +1,21 @@ +package test + +inline public fun String.run(p1: String? = null): String { + return this + p1 +} + +inline public fun String.run(p1: String = "", lambda: (a: String, b: Int) -> String, p2: Int = 0): String { + return lambda(p1, p2) + this +} + +public class Z(val value: Int = 0) { + + inline public fun String.run(p1: String? = null): String? { + return this + p1 + } + + inline public fun String.run(p1: String = "", lambda: (a: String, b: Int) -> String, p2: Int = 0): String { + return lambda(p1, p2) + this + } + +} \ No newline at end of file diff --git a/compiler/testData/codegen/boxInline/defaultValues/defaultMethodInClass.1.kt b/compiler/testData/codegen/boxInline/defaultValues/defaultMethodInClass.1.kt new file mode 100644 index 00000000000..f1822824496 --- /dev/null +++ b/compiler/testData/codegen/boxInline/defaultValues/defaultMethodInClass.1.kt @@ -0,0 +1,13 @@ +import test.* + +fun box(): String { + if (Z().run() != "null0") return "fail 1: ${Z().run()}" + + if (Z().run("OK") != "OK0") return "fail 2" + + if (Z().run("OK", {(a, b) -> a + b }, 1) != "OK1") return "fail 3" + + if (Z().run(lambda = {(a: String, b: Int) -> a + b }) != "0") return "fail 4" + + return "OK" +} diff --git a/compiler/testData/codegen/boxInline/defaultValues/defaultMethodInClass.2.kt b/compiler/testData/codegen/boxInline/defaultValues/defaultMethodInClass.2.kt new file mode 100644 index 00000000000..a881a5988db --- /dev/null +++ b/compiler/testData/codegen/boxInline/defaultValues/defaultMethodInClass.2.kt @@ -0,0 +1,13 @@ +package test + +public class Z(public val value: Int = 0) { + + inline public fun run(p1: String? = null): String? { + return p1 + value + } + + + inline public fun run(p1: String = "", lambda: (a: String, b: Int) -> String, p2: Int = 0): String { + return lambda(p1, p2) + } +} \ No newline at end of file diff --git a/compiler/testData/codegen/boxInline/defaultValues/simpleDefaultMethod.1.kt b/compiler/testData/codegen/boxInline/defaultValues/simpleDefaultMethod.1.kt index cb4936a747e..c48b5dedadc 100644 --- a/compiler/testData/codegen/boxInline/defaultValues/simpleDefaultMethod.1.kt +++ b/compiler/testData/codegen/boxInline/defaultValues/simpleDefaultMethod.1.kt @@ -18,5 +18,8 @@ fun box(): String { result = simple() if (result != "OK") return "fail2: ${result}" + var result2 = simpleDoubleFun(2.0) + if (result2 != 2.0 + 1.0) return "fail3: ${result2}" + return "OK" } \ No newline at end of file diff --git a/compiler/testData/codegen/boxInline/defaultValues/simpleDefaultMethod.2.kt b/compiler/testData/codegen/boxInline/defaultValues/simpleDefaultMethod.2.kt index 71ed00adaf0..21a2c0430b8 100644 --- a/compiler/testData/codegen/boxInline/defaultValues/simpleDefaultMethod.2.kt +++ b/compiler/testData/codegen/boxInline/defaultValues/simpleDefaultMethod.2.kt @@ -9,3 +9,9 @@ inline fun simpleFun(arg: String = "O"): String { return r; } + +inline fun simpleDoubleFun(arg: Double = 1.0): Double { + val r = arg + 1; + return r; +} + diff --git a/compiler/tests/org/jetbrains/jet/codegen/generated/BlackBoxInlineCodegenTestGenerated.java b/compiler/tests/org/jetbrains/jet/codegen/generated/BlackBoxInlineCodegenTestGenerated.java index 987b6dbd0de..8b7d284cb05 100644 --- a/compiler/tests/org/jetbrains/jet/codegen/generated/BlackBoxInlineCodegenTestGenerated.java +++ b/compiler/tests/org/jetbrains/jet/codegen/generated/BlackBoxInlineCodegenTestGenerated.java @@ -157,11 +157,21 @@ public class BlackBoxInlineCodegenTestGenerated extends AbstractBlackBoxCodegenT JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/boxInline/defaultValues"), Pattern.compile("^(.+)\\.1.kt$"), true); } + @TestMetadata("defaultInExtension.1.kt") + public void testDefaultInExtension() throws Exception { + doTestMultiFileWithInlineCheck("compiler/testData/codegen/boxInline/defaultValues/defaultInExtension.1.kt"); + } + @TestMetadata("defaultMethod.1.kt") public void testDefaultMethod() throws Exception { doTestMultiFileWithInlineCheck("compiler/testData/codegen/boxInline/defaultValues/defaultMethod.1.kt"); } + @TestMetadata("defaultMethodInClass.1.kt") + public void testDefaultMethodInClass() throws Exception { + doTestMultiFileWithInlineCheck("compiler/testData/codegen/boxInline/defaultValues/defaultMethodInClass.1.kt"); + } + @TestMetadata("inlineInDefaultParameter.1.kt") public void testInlineInDefaultParameter() throws Exception { doTestMultiFileWithInlineCheck("compiler/testData/codegen/boxInline/defaultValues/inlineInDefaultParameter.1.kt"); diff --git a/compiler/tests/org/jetbrains/jet/jvm/compiler/CompileKotlinAgainstInlineKotlinTestGenerated.java b/compiler/tests/org/jetbrains/jet/jvm/compiler/CompileKotlinAgainstInlineKotlinTestGenerated.java index 0b4700549a0..a5c2c5d55df 100644 --- a/compiler/tests/org/jetbrains/jet/jvm/compiler/CompileKotlinAgainstInlineKotlinTestGenerated.java +++ b/compiler/tests/org/jetbrains/jet/jvm/compiler/CompileKotlinAgainstInlineKotlinTestGenerated.java @@ -157,11 +157,21 @@ public class CompileKotlinAgainstInlineKotlinTestGenerated extends AbstractCompi JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/boxInline/defaultValues"), Pattern.compile("^(.+)\\.1.kt$"), true); } + @TestMetadata("defaultInExtension.1.kt") + public void testDefaultInExtension() throws Exception { + doBoxTestWithInlineCheck("compiler/testData/codegen/boxInline/defaultValues/defaultInExtension.1.kt"); + } + @TestMetadata("defaultMethod.1.kt") public void testDefaultMethod() throws Exception { doBoxTestWithInlineCheck("compiler/testData/codegen/boxInline/defaultValues/defaultMethod.1.kt"); } + @TestMetadata("defaultMethodInClass.1.kt") + public void testDefaultMethodInClass() throws Exception { + doBoxTestWithInlineCheck("compiler/testData/codegen/boxInline/defaultValues/defaultMethodInClass.1.kt"); + } + @TestMetadata("inlineInDefaultParameter.1.kt") public void testInlineInDefaultParameter() throws Exception { doBoxTestWithInlineCheck("compiler/testData/codegen/boxInline/defaultValues/inlineInDefaultParameter.1.kt");