Allow super calls in object declarations
This commit is contained in:
@@ -2256,8 +2256,6 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> implem
|
||||
public StackValue generateThisOrOuter(@NotNull ClassDescriptor calleeContainingClass, boolean isSuper) {
|
||||
boolean isSingleton = CodegenBinding.isSingleton(bindingContext, calleeContainingClass);
|
||||
if (isSingleton) {
|
||||
assert !isSuper;
|
||||
|
||||
if (context.hasThisDescriptor() && context.getThisDescriptor().equals(calleeContainingClass)) {
|
||||
return StackValue.local(0, typeMapper.mapType(calleeContainingClass));
|
||||
}
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
open class A (val s: Int) {
|
||||
open fun foo(): Int {
|
||||
return s
|
||||
}
|
||||
}
|
||||
|
||||
object Outer: A(1) {
|
||||
object O: A(2) {
|
||||
override fun foo(): Int {
|
||||
val s = super<A>.foo()
|
||||
return s + 3
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun box() : String {
|
||||
return if (Outer.O.foo() == 5) "OK" else "fail"
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
open class A {
|
||||
open fun foo(): Int {
|
||||
return 2
|
||||
}
|
||||
}
|
||||
|
||||
object O: A() {
|
||||
override fun foo(): Int {
|
||||
val s = super<A>.foo()
|
||||
return s + 3
|
||||
}
|
||||
}
|
||||
|
||||
fun box() : String {
|
||||
return if (O.foo() == 5) "OK" else "fail"
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
open class A {
|
||||
open fun foo(): Int {
|
||||
return 2
|
||||
}
|
||||
}
|
||||
|
||||
trait T {
|
||||
open fun foo(): Int {
|
||||
return 3
|
||||
}
|
||||
}
|
||||
|
||||
object O: A(), T {
|
||||
override fun foo(): Int {
|
||||
return super<A>.foo() + super<T>.foo()
|
||||
}
|
||||
}
|
||||
|
||||
fun box() : String {
|
||||
return if (O.foo() == 5) "OK" else "fail"
|
||||
}
|
||||
@@ -3531,6 +3531,11 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
|
||||
doTest("compiler/testData/codegen/box/objects/methodOnObject.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("nestedObjectWithSuperclass.kt")
|
||||
public void testNestedObjectWithSuperclass() throws Exception {
|
||||
doTest("compiler/testData/codegen/box/objects/nestedObjectWithSuperclass.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("objectLiteral.kt")
|
||||
public void testObjectLiteral() throws Exception {
|
||||
doTest("compiler/testData/codegen/box/objects/objectLiteral.kt");
|
||||
@@ -3541,6 +3546,16 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
|
||||
doTest("compiler/testData/codegen/box/objects/objectLiteralInClosure.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("objectWithSuperclass.kt")
|
||||
public void testObjectWithSuperclass() throws Exception {
|
||||
doTest("compiler/testData/codegen/box/objects/objectWithSuperclass.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("objectWithSuperclassAndTrait.kt")
|
||||
public void testObjectWithSuperclassAndTrait() throws Exception {
|
||||
doTest("compiler/testData/codegen/box/objects/objectWithSuperclassAndTrait.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("receiverInConstructor.kt")
|
||||
public void testReceiverInConstructor() throws Exception {
|
||||
doTest("compiler/testData/codegen/box/objects/receiverInConstructor.kt");
|
||||
|
||||
Reference in New Issue
Block a user