fixed critical bug with receiver used in constructor, field initializer
This commit is contained in:
@@ -810,6 +810,20 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
|
||||
constructorContext.lookupInContext(descriptor, null, state, true);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitThisExpression(JetThisExpression expression) {
|
||||
final DeclarationDescriptor descriptor = bindingContext.get(BindingContext.REFERENCE_TARGET, expression.getInstanceReference());
|
||||
if (descriptor instanceof ClassDescriptor) {
|
||||
// @todo for now all our classes are inner so no need to lookup this. change it when we have real inners
|
||||
}
|
||||
else {
|
||||
assert descriptor instanceof CallableDescriptor;
|
||||
if (context.getCallableDescriptorWithReceiver() != descriptor) {
|
||||
context.lookupInContext(descriptor, null, state, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
for (JetDeclaration declaration : myClass.getDeclarations()) {
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
open class A(open val v: String)
|
||||
|
||||
fun A.a(newv: String) = object: A("fail") {
|
||||
override val v = this@a.v + newv
|
||||
}
|
||||
|
||||
fun box() = A("O").a("K").v
|
||||
@@ -0,0 +1,10 @@
|
||||
open class A(open val v: String) {
|
||||
}
|
||||
|
||||
open class B(open val v: String) {
|
||||
fun a(newv: String) = object: A("fail") {
|
||||
override val v = this@B.v + newv
|
||||
}
|
||||
}
|
||||
|
||||
fun box() = B("O").a("K").v
|
||||
@@ -83,4 +83,12 @@ public class ObjectGenTest extends CodegenTestCase {
|
||||
public void testKt1737() {
|
||||
blackBoxFile("regressions/kt1737.kt");
|
||||
}
|
||||
|
||||
public void testReceiverInConstructor() {
|
||||
blackBoxFile("objects/receiverInConstructor.kt");
|
||||
}
|
||||
|
||||
public void testThisInConstructor() {
|
||||
blackBoxFile("objects/thisInConstructor.kt");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user