KT-3573 "Error generating primary constructor" when trying to use "this" in extensions from constructors

#KT-3573 Fixed
This commit is contained in:
Mikhael Bogdanov
2013-09-17 15:38:46 +04:00
parent fe7b5cc532
commit 8ffee527d7
4 changed files with 47 additions and 1 deletions
@@ -1260,7 +1260,7 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
else {
assert descriptor instanceof CallableDescriptor;
if (context.getCallableDescriptorWithReceiver() != descriptor) {
context.lookupInContext(descriptor, null, state, false);
context.lookupInContext(descriptor, null, state, true);
}
}
}
@@ -0,0 +1,12 @@
class Data
fun newInit(f: Data.() -> Data) = Data().f()
class TestClass {
val test: Data = newInit() { this }
}
fun box() : String {
TestClass()
return "OK"
}
@@ -0,0 +1,24 @@
class Comment() {
var article = ""
}
fun new(body: Comment.() -> Unit) : Comment {
val c = Comment()
c.body()
return c
}
open class Request(val handler : Any.() -> Comment) {
val s = handler().article
}
class A : Request ({
new {
this.article = "OK"
}
})
fun box() : String {
return A().s
}
@@ -2349,6 +2349,16 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
doTest("compiler/testData/codegen/box/functions/kt3313.kt");
}
@TestMetadata("kt3573.kt")
public void testKt3573() throws Exception {
doTest("compiler/testData/codegen/box/functions/kt3573.kt");
}
@TestMetadata("kt3724.kt")
public void testKt3724() throws Exception {
doTest("compiler/testData/codegen/box/functions/kt3724.kt");
}
@TestMetadata("kt395.kt")
public void testKt395() throws Exception {
doTest("compiler/testData/codegen/box/functions/kt395.kt");