Do not substitute arguments while replacing them

It prevents from creating complicated types
This commit is contained in:
Denis Zharkov
2015-08-04 14:28:14 +03:00
parent 32c23728b3
commit 51668b4cc3
9 changed files with 15 additions and 17 deletions
@@ -1,6 +1,6 @@
package
internal fun foo(/*0*/ p: X): (Bad<(Bad<Bad<*>!>..Bad<out Bad<*>!>?)>..Bad<out (Bad<Bad<*>!>..Bad<out Bad<*>!>?)>?)
internal fun foo(/*0*/ p: X): (Bad<Bad<*>!>..Bad<out Bad<*>!>?)
public/*package*/ open class Bad</*0*/ T : (Bad<Bad<*>>..Bad<out Bad<*>>?)> {
public/*package*/ constructor Bad</*0*/ T : (Bad<Bad<*>>..Bad<out Bad<*>>?)>()
@@ -12,7 +12,7 @@ public/*package*/ open class Bad</*0*/ T : (Bad<Bad<*>>..Bad<out Bad<*>>?)> {
public/*package*/ open class X {
public/*package*/ constructor X()
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
public/*package*/ open fun foo(): (Bad<(Bad<Bad<*>!>..Bad<out Bad<*>!>?)>..Bad<out (Bad<Bad<*>!>..Bad<out Bad<*>!>?)>?)
public/*package*/ open fun foo(): (Bad<Bad<*>!>..Bad<out Bad<*>!>?)
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
}
@@ -30,5 +30,5 @@ public/*package*/ open class Test {
}
// Static members
public/*package*/ final var rawAField: (A<(A<A<*, *, *>!, A<*, *, *>!, kotlin.(Mutable)List<*>!>..A<out A<*, *, *>!, out A<*, *, *>!, out kotlin.(Mutable)List<*>!>?), (A<A<*, *, *>!, A<*, *, *>!, kotlin.(Mutable)List<*>!>..A<out A<*, *, *>!, out A<*, *, *>!, out kotlin.(Mutable)List<*>!>?), (kotlin.MutableList<kotlin.Any?>..kotlin.List<*>?)>..A<out (A<A<*, *, *>!, A<*, *, *>!, kotlin.(Mutable)List<*>!>..A<out A<*, *, *>!, out A<*, *, *>!, out kotlin.(Mutable)List<*>!>?), out (A<A<*, *, *>!, A<*, *, *>!, kotlin.(Mutable)List<*>!>..A<out A<*, *, *>!, out A<*, *, *>!, out kotlin.(Mutable)List<*>!>?), out (kotlin.MutableList<kotlin.Any?>..kotlin.List<*>?)>?)
public/*package*/ final var rawAField: (A<A<*, *, *>!, A<*, *, *>!, kotlin.(Mutable)List<*>!>..A<out A<*, *, *>!, out A<*, *, *>!, out kotlin.(Mutable)List<*>!>?)
}
@@ -28,5 +28,5 @@ public open class Test {
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
// Static members
public/*package*/ final var rawB: (B<(A<kotlin.Any!>..A<*>?)>..B<out (A<kotlin.Any!>..A<*>?)>?)
public/*package*/ final var rawB: (B<A<*>!>..B<out A<*>!>?)
}
@@ -9,5 +9,5 @@ public/*package*/ open class Test {
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
// Static members
public/*package*/ open fun foo(/*0*/ x: (kotlin.Comparable<in kotlin.Any?>..kotlin.Comparable<in kotlin.Nothing>?)): kotlin.Unit
public/*package*/ open fun foo(/*0*/ x: (kotlin.Comparable<kotlin.Any?>..kotlin.Comparable<kotlin.Nothing>?)): kotlin.Unit
}
@@ -23,5 +23,5 @@ public/*package*/ open class Test {
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
// Static members
public/*package*/ open fun foo(/*0*/ x: (B<(A<kotlin.CharSequence!>..A<*>?)>..B<out (A<kotlin.CharSequence!>..A<*>?)>?)): kotlin.Unit
public/*package*/ open fun foo(/*0*/ x: (B<A<*>!>..B<out A<*>!>?)): kotlin.Unit
}
@@ -6,7 +6,7 @@ public open class RawSuperTypeWithRecursiveBound {
public open inner class Derived : test.RawSuperTypeWithRecursiveBound.Super<out test.RawSuperTypeWithRecursiveBound.Super<*>!> {
public constructor Derived()
public open override /*1*/ fun dummy(): kotlin.Unit
public open override /*1*/ fun foo(/*0*/ p0: (test.RawSuperTypeWithRecursiveBound.Super<(test.RawSuperTypeWithRecursiveBound.Super<test.RawSuperTypeWithRecursiveBound.Super<*>!>..test.RawSuperTypeWithRecursiveBound.Super<out test.RawSuperTypeWithRecursiveBound.Super<*>!>?)>..test.RawSuperTypeWithRecursiveBound.Super<out (test.RawSuperTypeWithRecursiveBound.Super<test.RawSuperTypeWithRecursiveBound.Super<*>!>..test.RawSuperTypeWithRecursiveBound.Super<out test.RawSuperTypeWithRecursiveBound.Super<*>!>?)>?)): kotlin.Unit
public open override /*1*/ fun foo(/*0*/ p0: (test.RawSuperTypeWithRecursiveBound.Super<test.RawSuperTypeWithRecursiveBound.Super<*>!>..test.RawSuperTypeWithRecursiveBound.Super<out test.RawSuperTypeWithRecursiveBound.Super<*>!>?)): kotlin.Unit
public open fun foo(/*0*/ p0: kotlin.Any!): kotlin.Unit
}
@@ -6,7 +6,7 @@ public open class RawSuperTypeWithRecursiveBoundMultipleParameters {
public open inner class Derived : test.RawSuperTypeWithRecursiveBoundMultipleParameters.Super<kotlin.Any!, out test.RawSuperTypeWithRecursiveBoundMultipleParameters.Super<*, *>!> {
public constructor Derived()
public open override /*1*/ fun dummy(): kotlin.Unit
public open override /*1*/ fun foo(/*0*/ p0: kotlin.Any!, /*1*/ p1: (test.RawSuperTypeWithRecursiveBoundMultipleParameters.Super<kotlin.Any!, (test.RawSuperTypeWithRecursiveBoundMultipleParameters.Super<kotlin.Any!, test.RawSuperTypeWithRecursiveBoundMultipleParameters.Super<*, *>!>..test.RawSuperTypeWithRecursiveBoundMultipleParameters.Super<*, out test.RawSuperTypeWithRecursiveBoundMultipleParameters.Super<*, *>!>?)>..test.RawSuperTypeWithRecursiveBoundMultipleParameters.Super<*, out (test.RawSuperTypeWithRecursiveBoundMultipleParameters.Super<kotlin.Any!, test.RawSuperTypeWithRecursiveBoundMultipleParameters.Super<*, *>!>..test.RawSuperTypeWithRecursiveBoundMultipleParameters.Super<*, out test.RawSuperTypeWithRecursiveBoundMultipleParameters.Super<*, *>!>?)>?)): kotlin.Unit
public open override /*1*/ fun foo(/*0*/ p0: kotlin.Any!, /*1*/ p1: (test.RawSuperTypeWithRecursiveBoundMultipleParameters.Super<kotlin.Any!, test.RawSuperTypeWithRecursiveBoundMultipleParameters.Super<*, *>!>..test.RawSuperTypeWithRecursiveBoundMultipleParameters.Super<*, out test.RawSuperTypeWithRecursiveBoundMultipleParameters.Super<*, *>!>?)): kotlin.Unit
public open fun foo(/*0*/ p0: kotlin.Any!, /*1*/ p1: kotlin.Any!): kotlin.Unit
}
@@ -98,7 +98,7 @@ private fun JetType.enhanceInflexible(qualifiers: (Int) -> JavaTypeQualifiers, i
enhancedNullabilityAnnotations
).filterNotNull().compositeAnnotationsOrSingle()
val (newSubstitution, substitutedEnhancedArgs) = computeNewSubstitutionAndArguments(
val newSubstitution = computeNewSubstitution(
typeConstructor.parameters, enhancedArguments
)
@@ -106,7 +106,7 @@ private fun JetType.enhanceInflexible(qualifiers: (Int) -> JavaTypeQualifiers, i
newAnnotations,
typeConstructor,
enhancedNullability,
substitutedEnhancedArgs,
enhancedArguments,
newSubstitution,
if (enhancedClassifier is ClassDescriptor)
enhancedClassifier.getMemberScope(newSubstitution)
@@ -91,25 +91,23 @@ public class IndexedParametersSubstitution(
}
}
public fun JetType.computeNewSubstitutionAndArguments(
public fun JetType.computeNewSubstitution(
newParameters: List<TypeParameterDescriptor>,
newArguments: List<TypeProjection>
): Pair<TypeSubstitution, List<TypeProjection>> {
): TypeSubstitution {
val previousSubstitution = getSubstitution()
if (newArguments.isEmpty()) return Pair(previousSubstitution, emptyList())
if (newArguments.isEmpty()) return previousSubstitution
val newIndexedSubstitution = IndexedParametersSubstitution(newParameters, newArguments)
// If previous substitution was trivial just replace it with indexed one
if (previousSubstitution is IndexedParametersSubstitution || previousSubstitution.isEmpty()) {
return Pair(newIndexedSubstitution, newArguments)
return newIndexedSubstitution
}
val composedSubstitution = CompositeTypeSubstitution(newIndexedSubstitution, previousSubstitution)
val newSubstitutor = composedSubstitution.buildSubstitutor()
val resultArguments = newParameters.map { newSubstitutor.substitute(TypeProjectionImpl(it.variance, it.defaultType))!! }
return Pair(composedSubstitution, resultArguments)
return composedSubstitution
}
private class CompositeTypeSubstitution(