Fix for KT-11634: UOE in ConstructorContext.getOuterExpression for super call in delegation
#KT-11634 Fixed
This commit is contained in:
@@ -1274,6 +1274,18 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitSuperExpression(@NotNull KtSuperExpression expression) {
|
||||
KotlinType thisTypeForSuperCall = bindingContext.get(BindingContext.THIS_TYPE_FOR_SUPER_EXPRESSION, expression);
|
||||
assert thisTypeForSuperCall != null : "This type for superCall ''" + expression.getText() + "'' should be not null!";
|
||||
ClassifierDescriptor descriptor = thisTypeForSuperCall.getConstructor().getDeclarationDescriptor();
|
||||
assert descriptor instanceof ClassDescriptor :
|
||||
"'This' reference target for ''" + expression.getText() + "''should be class descriptor, but was " + descriptor;
|
||||
if (descriptor instanceof ClassDescriptor) {
|
||||
lookupInContext(descriptor);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
for (KtDeclaration declaration : myClass.getDeclarations()) {
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
interface A {
|
||||
fun foo(): String
|
||||
}
|
||||
|
||||
class AImpl(val z: String) : A {
|
||||
override fun foo(): String = z
|
||||
}
|
||||
|
||||
open class AFabric {
|
||||
open fun createA(): A = AImpl("OK")
|
||||
}
|
||||
|
||||
class AWrapperFabric : AFabric() {
|
||||
|
||||
override fun createA(): A {
|
||||
return AImpl("fail")
|
||||
}
|
||||
|
||||
fun createMyA(): A {
|
||||
return object : A by super.createA() {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
return AWrapperFabric().createMyA().foo()
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
interface A {
|
||||
fun foo(): String
|
||||
}
|
||||
|
||||
class AImpl(val z: String) : A {
|
||||
override fun foo(): String = z
|
||||
}
|
||||
|
||||
open class AFabric {
|
||||
open fun createA(z: String): A = AImpl(z)
|
||||
}
|
||||
|
||||
class AWrapperFabric : AFabric() {
|
||||
|
||||
override fun createA(z: String): A {
|
||||
return AImpl("fail: $z")
|
||||
}
|
||||
|
||||
fun createMyA(): A {
|
||||
val z = "OK"
|
||||
return object : A by super.createA(z) {}
|
||||
}
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
return AWrapperFabric().createMyA().foo()
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
interface A {
|
||||
fun foo(): String
|
||||
}
|
||||
|
||||
class AImpl(val z: String) : A {
|
||||
override fun foo(): String = z
|
||||
}
|
||||
|
||||
open class AFabric {
|
||||
open fun createA(z: String): A = AImpl(z)
|
||||
}
|
||||
|
||||
class AWrapperFabric : AFabric() {
|
||||
|
||||
override fun createA(z: String): A {
|
||||
return AImpl("fail: $z")
|
||||
}
|
||||
|
||||
fun createMyA(): A {
|
||||
val z = "OK"
|
||||
return object : A by super<AFabric>@AWrapperFabric.createA(z) {}
|
||||
}
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
return AWrapperFabric().createMyA().foo()
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
interface A {
|
||||
fun foo(): String
|
||||
}
|
||||
|
||||
open class Base (val p: String) {
|
||||
open val a = object : A {
|
||||
override fun foo(): String {
|
||||
return p
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
open class Derived1 (p: String): Base(p) {
|
||||
override open val a = object : A {
|
||||
override fun foo(): String {
|
||||
return "fail"
|
||||
}
|
||||
}
|
||||
|
||||
inner class Derived2(p: String) : Base(p) {
|
||||
val x = object : A by super<Base>@Derived1.a {}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
return Derived1("OK").Derived2("fail").x.foo()
|
||||
}
|
||||
@@ -3136,6 +3136,30 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("kt11634.kt")
|
||||
public void testKt11634() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/closures/kt11634.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("kt11634_2.kt")
|
||||
public void testKt11634_2() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/closures/kt11634_2.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("kt11634_3.kt")
|
||||
public void testKt11634_3() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/closures/kt11634_3.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("kt11634_4.kt")
|
||||
public void testKt11634_4() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/closures/kt11634_4.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("kt2151.kt")
|
||||
public void testKt2151() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/closures/kt2151.kt");
|
||||
|
||||
Reference in New Issue
Block a user