Fix for KT-14243: Wrong invocation descriptor on calling implicitly generated implementation in class
#KT-14243 Fixed
This commit is contained in:
@@ -591,6 +591,37 @@ public class KotlinTypeMapper {
|
|||||||
return Variance.OUT_VARIANCE;
|
return Variance.OUT_VARIANCE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//NB: similar platform agnostic code in DescriptorUtils.unwrapFakeOverride
|
||||||
|
private FunctionDescriptor findSuperDeclaration(@NotNull FunctionDescriptor descriptor, boolean isSuperCall) {
|
||||||
|
while (descriptor.getKind() == CallableMemberDescriptor.Kind.FAKE_OVERRIDE) {
|
||||||
|
Collection<? extends FunctionDescriptor> overridden = descriptor.getOverriddenDescriptors();
|
||||||
|
if (overridden.isEmpty()) {
|
||||||
|
throw new IllegalStateException("Fake override should have at least one overridden descriptor: " + descriptor);
|
||||||
|
}
|
||||||
|
|
||||||
|
FunctionDescriptor classCallable = null;
|
||||||
|
for (FunctionDescriptor overriddenFunction : overridden) {
|
||||||
|
if (!isInterface(overriddenFunction.getContainingDeclaration())) {
|
||||||
|
classCallable = overriddenFunction;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (classCallable != null) {
|
||||||
|
//prefer class callable cause of else branch
|
||||||
|
descriptor = classCallable;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
else if (isSuperCall && !isJvm8Target && !isInterface(descriptor.getContainingDeclaration())) {
|
||||||
|
//Don't unwrap fake overrides from class to interface cause substituted override would be implicitly generated for target 1.6
|
||||||
|
return descriptor;
|
||||||
|
}
|
||||||
|
|
||||||
|
descriptor = overridden.iterator().next();
|
||||||
|
}
|
||||||
|
return descriptor;
|
||||||
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public CallableMethod mapToCallableMethod(@NotNull FunctionDescriptor descriptor, boolean superCall) {
|
public CallableMethod mapToCallableMethod(@NotNull FunctionDescriptor descriptor, boolean superCall) {
|
||||||
if (descriptor instanceof ConstructorDescriptor) {
|
if (descriptor instanceof ConstructorDescriptor) {
|
||||||
@@ -609,7 +640,7 @@ public class KotlinTypeMapper {
|
|||||||
|
|
||||||
DeclarationDescriptor functionParent = descriptor.getOriginal().getContainingDeclaration();
|
DeclarationDescriptor functionParent = descriptor.getOriginal().getContainingDeclaration();
|
||||||
|
|
||||||
FunctionDescriptor functionDescriptor = unwrapFakeOverride(descriptor.getOriginal());
|
FunctionDescriptor functionDescriptor = findSuperDeclaration(descriptor.getOriginal(), superCall);
|
||||||
|
|
||||||
JvmMethodSignature signature;
|
JvmMethodSignature signature;
|
||||||
Type owner;
|
Type owner;
|
||||||
|
|||||||
+18
@@ -0,0 +1,18 @@
|
|||||||
|
interface Z<T> {
|
||||||
|
fun test(p: T): T {
|
||||||
|
return p
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
open class ZImpl : Z<String>
|
||||||
|
|
||||||
|
class ZImpl2 : ZImpl() {
|
||||||
|
|
||||||
|
override fun test(p: String): String {
|
||||||
|
return super.test(p)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun box(): String {
|
||||||
|
return ZImpl2().test("OK")
|
||||||
|
}
|
||||||
@@ -0,0 +1,20 @@
|
|||||||
|
interface Z<T> {
|
||||||
|
fun test(p: T): T {
|
||||||
|
return p
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
open class ZImpl : Z<String>
|
||||||
|
|
||||||
|
open class ZImpl2 : Z<String>, ZImpl()
|
||||||
|
|
||||||
|
class ZImpl3 : ZImpl2() {
|
||||||
|
|
||||||
|
override fun test(p: String): String {
|
||||||
|
return super.test(p)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun box(): String {
|
||||||
|
return ZImpl3().test("OK")
|
||||||
|
}
|
||||||
@@ -0,0 +1,20 @@
|
|||||||
|
|
||||||
|
open class Z<T, Y> {
|
||||||
|
open fun test(p: T, z: Y): T {
|
||||||
|
return p
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
open class ZImpl<X> : Z<String, X>()
|
||||||
|
|
||||||
|
open class ZImpl2 : ZImpl<String>()
|
||||||
|
|
||||||
|
class ZImpl3 : ZImpl2() {
|
||||||
|
override fun test(p: String, z: String): String {
|
||||||
|
return super.test(p, z)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun box(): String {
|
||||||
|
return ZImpl3().test("OK", "fail")
|
||||||
|
}
|
||||||
@@ -0,0 +1,21 @@
|
|||||||
|
interface Z<T> {
|
||||||
|
val value: T
|
||||||
|
|
||||||
|
val z: T
|
||||||
|
get() = value
|
||||||
|
}
|
||||||
|
|
||||||
|
open class ZImpl : Z<String> {
|
||||||
|
override val value: String
|
||||||
|
get() = "OK"
|
||||||
|
}
|
||||||
|
|
||||||
|
open class ZImpl2 : ZImpl() {
|
||||||
|
override val z: String
|
||||||
|
get() = super.z
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
fun box(): String {
|
||||||
|
return ZImpl2().value
|
||||||
|
}
|
||||||
@@ -0,0 +1,20 @@
|
|||||||
|
// JVM_TARGET: 1.8
|
||||||
|
|
||||||
|
interface Z<T> {
|
||||||
|
fun test(p: T): T {
|
||||||
|
return p
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
open class ZImpl : Z<String>
|
||||||
|
|
||||||
|
class ZImpl2 : ZImpl() {
|
||||||
|
|
||||||
|
override fun test(p: String): String {
|
||||||
|
return super.test(p)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun box(): String {
|
||||||
|
return ZImpl2().test("OK")
|
||||||
|
}
|
||||||
@@ -0,0 +1,22 @@
|
|||||||
|
// JVM_TARGET: 1.8
|
||||||
|
|
||||||
|
interface Z<T> {
|
||||||
|
fun test(p: T): T {
|
||||||
|
return p
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
open class ZImpl : Z<String>
|
||||||
|
|
||||||
|
open class ZImpl2 : Z<String>, ZImpl()
|
||||||
|
|
||||||
|
class ZImpl3 : ZImpl2() {
|
||||||
|
|
||||||
|
override fun test(p: String): String {
|
||||||
|
return super.test(p)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun box(): String {
|
||||||
|
return ZImpl3().test("OK")
|
||||||
|
}
|
||||||
@@ -0,0 +1,23 @@
|
|||||||
|
// JVM_TARGET: 1.8
|
||||||
|
|
||||||
|
interface Z<T> {
|
||||||
|
val value: T
|
||||||
|
|
||||||
|
val z: T
|
||||||
|
get() = value
|
||||||
|
}
|
||||||
|
|
||||||
|
open class ZImpl : Z<String> {
|
||||||
|
override val value: String
|
||||||
|
get() = "OK"
|
||||||
|
}
|
||||||
|
|
||||||
|
open class ZImpl2 : ZImpl() {
|
||||||
|
override val z: String
|
||||||
|
get() = super.z
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
fun box(): String {
|
||||||
|
return ZImpl2().value
|
||||||
|
}
|
||||||
+18
@@ -151,6 +151,24 @@ public class BlackBoxWithJava8CodegenTestGenerated extends AbstractBlackBoxCodeg
|
|||||||
doTest(fileName);
|
doTest(fileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("kt14243.kt")
|
||||||
|
public void testKt14243() throws Exception {
|
||||||
|
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/java8/box/jvm8/kt14243.kt");
|
||||||
|
doTest(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("kt14243_2.kt")
|
||||||
|
public void testKt14243_2() throws Exception {
|
||||||
|
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/java8/box/jvm8/kt14243_2.kt");
|
||||||
|
doTest(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("kt14243_prop.kt")
|
||||||
|
public void testKt14243_prop() throws Exception {
|
||||||
|
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/java8/box/jvm8/kt14243_prop.kt");
|
||||||
|
doTest(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("oneImplementation.kt")
|
@TestMetadata("oneImplementation.kt")
|
||||||
public void testOneImplementation() throws Exception {
|
public void testOneImplementation() throws Exception {
|
||||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/java8/box/jvm8/oneImplementation.kt");
|
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/java8/box/jvm8/oneImplementation.kt");
|
||||||
|
|||||||
@@ -15187,6 +15187,30 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
|
|||||||
doTest(fileName);
|
doTest(fileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("kt14243.kt")
|
||||||
|
public void testKt14243() throws Exception {
|
||||||
|
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/super/kt14243.kt");
|
||||||
|
doTest(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("kt14243_2.kt")
|
||||||
|
public void testKt14243_2() throws Exception {
|
||||||
|
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/super/kt14243_2.kt");
|
||||||
|
doTest(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("kt14243_class.kt")
|
||||||
|
public void testKt14243_class() throws Exception {
|
||||||
|
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/super/kt14243_class.kt");
|
||||||
|
doTest(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("kt14243_prop.kt")
|
||||||
|
public void testKt14243_prop() throws Exception {
|
||||||
|
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/super/kt14243_prop.kt");
|
||||||
|
doTest(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("kt3492ClassFun.kt")
|
@TestMetadata("kt3492ClassFun.kt")
|
||||||
public void testKt3492ClassFun() throws Exception {
|
public void testKt3492ClassFun() throws Exception {
|
||||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/super/kt3492ClassFun.kt");
|
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/super/kt3492ClassFun.kt");
|
||||||
|
|||||||
@@ -101,6 +101,30 @@ public class SuperTestGenerated extends AbstractSuperTest {
|
|||||||
doTest(fileName);
|
doTest(fileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("kt14243.kt")
|
||||||
|
public void testKt14243() throws Exception {
|
||||||
|
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/super/kt14243.kt");
|
||||||
|
doTest(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("kt14243_2.kt")
|
||||||
|
public void testKt14243_2() throws Exception {
|
||||||
|
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/super/kt14243_2.kt");
|
||||||
|
doTest(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("kt14243_class.kt")
|
||||||
|
public void testKt14243_class() throws Exception {
|
||||||
|
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/super/kt14243_class.kt");
|
||||||
|
doTest(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("kt14243_prop.kt")
|
||||||
|
public void testKt14243_prop() throws Exception {
|
||||||
|
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/super/kt14243_prop.kt");
|
||||||
|
doTest(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("kt3492ClassFun.kt")
|
@TestMetadata("kt3492ClassFun.kt")
|
||||||
public void testKt3492ClassFun() throws Exception {
|
public void testKt3492ClassFun() throws Exception {
|
||||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/super/kt3492ClassFun.kt");
|
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/super/kt3492ClassFun.kt");
|
||||||
|
|||||||
Reference in New Issue
Block a user