Use doSubstitute when enhacing types of Java method

Before this commit old type parameters were inserted into new descriptor,
and that broke a simple contract: desc.child.getContainingDeclaration() == desc.

We use `doSubstitute` here because it does exactly what we need:
1. creates full copy of descriptor
2. copies method's type parameters (with new containing declaration) and properly substitute to them in value parameters, return type and etc.

But we had to customize `doSubstitute`: add some parameters like `newReturnType`

NOTE: Strange testData change.
(Mutable)List<in T!>! after substitution becomes MutableList<in T!>..List<*>?.

But it's not wrong because List<in T> behaves exactly as List<*>, and the same happens when substituing Java class scope:
public class A<E> {
    <T> void foo(List<? super T> x) {}
}

Kotlin:
A.foo(), type of first value parameter --- (Mutable)List<in T!>
A<String>().foo(), type of first value parameter --- MutableList<in T!>..List<*>?
This commit is contained in:
Denis Zharkov
2015-07-08 10:51:36 +03:00
parent f6c4ec1533
commit c01c59d562
6 changed files with 56 additions and 18 deletions

View File

@@ -2,5 +2,5 @@ package test
public open class MethodWithMappedClasses {
public constructor MethodWithMappedClasses()
public open fun </*0*/ T> copy(/*0*/ dest: kotlin.(Mutable)List<in T!>!, /*1*/ src: kotlin.(Mutable)List<T!>!): kotlin.Unit
public open fun </*0*/ T> copy(/*0*/ dest: (kotlin.MutableList<in T!>..kotlin.List<*>?), /*1*/ src: kotlin.(Mutable)List<T!>!): kotlin.Unit
}

View File

@@ -2,5 +2,5 @@ package test
public open class MethodWithTypeParameters {
public constructor MethodWithTypeParameters()
public open fun </*0*/ A, /*1*/ B : java.lang.Runnable!> foo(/*0*/ a: A!, /*1*/ b: (kotlin.MutableList<out B!>..kotlin.List<B!>?), /*2*/ c: kotlin.(Mutable)List<in kotlin.String!>!): kotlin.Unit where B : kotlin.(Mutable)List<kotlin.Cloneable!>!
public open fun </*0*/ A, /*1*/ B : java.lang.Runnable!> foo(/*0*/ a: A!, /*1*/ b: (kotlin.MutableList<out B!>..kotlin.List<B!>?), /*2*/ c: (kotlin.MutableList<in kotlin.String!>..kotlin.List<*>?)): kotlin.Unit where B : kotlin.(Mutable)List<kotlin.Cloneable!>!
}