KT-3374 Wrong this@method receiver

This commit is contained in:
Mikhael Bogdanov
2013-02-28 14:30:25 +04:00
parent bd4d939089
commit 6e1e495397
3 changed files with 21 additions and 1 deletions
@@ -1024,7 +1024,7 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
if (captureReceiver != null) {
iv.load(0, OBJECT_TYPE);
final Type asmType = typeMapper.mapType(captureReceiver.getDefaultType(), JetTypeMapperMode.IMPL);
iv.load(1, asmType);
iv.load(k, asmType);
iv.putfield(internalName, CAPTURED_RECEIVER_FIELD, asmType.getDescriptor());
k += asmType.getSize();
}
@@ -0,0 +1,15 @@
class Test {
private fun <T : Any> T.self() = object{
fun calc() : T {
return this@self
}
}
fun box() : Int {
return 1.self().calc() + 1
}
}
fun box() : String {
return if (Test().box() == 2) "OK" else "fail"
}
@@ -1577,6 +1577,11 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
doTest("compiler/testData/codegen/box/extensionFunctions/simple.kt");
}
@TestMetadata("thisMethodInObjectLiteral.kt")
public void testThisMethodInObjectLiteral() throws Exception {
doTest("compiler/testData/codegen/box/extensionFunctions/thisMethodInObjectLiteral.kt");
}
@TestMetadata("virtual.kt")
public void testVirtual() throws Exception {
doTest("compiler/testData/codegen/box/extensionFunctions/virtual.kt");