From 602aea04672785fb68634c94e4bced3c6cbf0b5c Mon Sep 17 00:00:00 2001 From: Alex Tkachman Date: Thu, 8 Dec 2011 19:22:09 +0200 Subject: [PATCH] KT-707 default params for constructors --- .../src/org/jetbrains/jet/codegen/FunctionCodegen.java | 8 ++++++-- compiler/testData/codegen/regressions/kt707.jet | 9 +++++++++ .../tests/org/jetbrains/jet/codegen/ClassGenTest.java | 4 ++++ 3 files changed, 19 insertions(+), 2 deletions(-) create mode 100644 compiler/testData/codegen/regressions/kt707.jet diff --git a/compiler/backend/src/org/jetbrains/jet/codegen/FunctionCodegen.java b/compiler/backend/src/org/jetbrains/jet/codegen/FunctionCodegen.java index cb0248c318d..a53849fd83b 100644 --- a/compiler/backend/src/org/jetbrains/jet/codegen/FunctionCodegen.java +++ b/compiler/backend/src/org/jetbrains/jet/codegen/FunctionCodegen.java @@ -366,8 +366,12 @@ public class FunctionCodegen { if(kind == OwnerKind.TRAIT_IMPL) { iv.invokeinterface(ownerInternalName, jvmSignature.getName(), jvmSignature.getDescriptor()); } - else - iv.invokevirtual(ownerInternalName, jvmSignature.getName(), jvmSignature.getDescriptor()); + else { + if(!isConstructor) + iv.invokevirtual(ownerInternalName, jvmSignature.getName(), jvmSignature.getDescriptor()); + else + iv.invokespecial(ownerInternalName, jvmSignature.getName(), jvmSignature.getDescriptor()); + } } else { iv.invokestatic(ownerInternalName, jvmSignature.getName(), jvmSignature.getDescriptor()); diff --git a/compiler/testData/codegen/regressions/kt707.jet b/compiler/testData/codegen/regressions/kt707.jet new file mode 100644 index 00000000000..47d245455aa --- /dev/null +++ b/compiler/testData/codegen/regressions/kt707.jet @@ -0,0 +1,9 @@ +class List(val head: T, val tail: List? = null) + +fun List.mapHead(f: fun(T): T): List = List(f(head), null) + +fun box() : String { + val a: Int = List(1).mapHead{it * 2}.head + System.out?.println(a) + return "OK" +} \ No newline at end of file diff --git a/compiler/tests/org/jetbrains/jet/codegen/ClassGenTest.java b/compiler/tests/org/jetbrains/jet/codegen/ClassGenTest.java index 0de47ea91ab..25c697c6484 100644 --- a/compiler/tests/org/jetbrains/jet/codegen/ClassGenTest.java +++ b/compiler/tests/org/jetbrains/jet/codegen/ClassGenTest.java @@ -225,4 +225,8 @@ public class ClassGenTest extends CodegenTestCase { public void testKt285 () throws Exception { // blackBoxFile("regressions/kt285.jet"); } + + public void testKt707 () throws Exception { + blackBoxFile("regressions/kt707.jet"); + } }