#KT-3023 Fixed

This commit is contained in:
Alexey Sedunov
2012-11-07 18:33:21 +04:00
parent 415b6f8efe
commit 8cff709bfb
4 changed files with 47 additions and 1 deletions
@@ -681,6 +681,13 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
assert function.getValueParameters().size() == constructor.getValueParameters().size() :
"Number of parameters of copy function and constructor are different. Copy: " + function.getValueParameters().size() + ", constructor: " + constructor.getValueParameters().size();
MutableClosure closure = context.closure;
if (closure != null && closure.getCaptureThis() != null) {
final Type type = typeMapper.mapType(enclosingClassDescriptor(bindingContext, descriptor));
iv.load(0, classAsmType);
iv.getfield(JvmClassName.byType(classAsmType).getInternalName(), CAPTURED_THIS_FIELD, type.getDescriptor());
}
int parameterIndex = 0;
for (ValueParameterDescriptor parameterDescriptor : function.getValueParameters()) {
iv.load(parameterIndex + 1, typeMapper.mapType(parameterDescriptor.getType()));
@@ -0,0 +1,15 @@
class Bar(val name: String)
class Baz {
class Foo() {
data class NestedFoo(val bar: Bar)
fun foo(): String {
return NestedFoo(Bar("FAIL")).copy(bar = Bar("OK")).bar.name
}
}
}
fun box(): String {
return Baz().Foo().foo()
}
@@ -0,0 +1,15 @@
class Bar(val name: String)
abstract class Foo {
public abstract fun foo(): String
}
fun box(): String {
return object: Foo() {
data class NestedFoo(val bar: Bar)
override fun foo(): String {
return NestedFoo(Bar("Fail")).copy(bar = Bar("OK")).bar.name
}
}.foo()
}
@@ -112,7 +112,16 @@ public class DataClassCodegenTestGenerated extends AbstractDataClassCodegenTest
public void testWithGenericParameter() throws Exception {
blackBoxFileByFullPath("compiler/testData/codegen/dataClasses/copy/withGenericParameter.kt");
}
@TestMetadata("copyInNestedDataClass.kt")
public void testCopyInNestedClasses() throws Exception {
blackBoxFileByFullPath("compiler/testData/codegen/dataClasses/copy/copyInNestedDataClass.kt");
}
@TestMetadata("copyInObjectNestedDataClass.kt")
public void testCopyInObjectNestedClasses() throws Exception {
blackBoxFileByFullPath("compiler/testData/codegen/dataClasses/copy/copyInObjectNestedDataClass.kt");
}
}
@TestMetadata("compiler/testData/codegen/dataClasses/equals")