substitute upper bounds after creating all substitutions for type parameters

(otherwise it doesn't work for forward references)
This commit is contained in:
Svetlana Isakova
2013-01-18 17:47:04 +04:00
parent 8f59172f27
commit ff01fad3cd
2 changed files with 8 additions and 4 deletions
@@ -66,7 +66,7 @@ public class DescriptorSubstitutor {
return "DescriptorSubstitutor.substituteTypeParameters(" + mutableSubstitution + " / " + originalSubstitutor.getSubstitution() + ")";
}
});
Map<TypeParameterDescriptor, TypeParameterDescriptorImpl> substitutedMap = Maps.newHashMap();
for (TypeParameterDescriptor descriptor : typeParameters) {
TypeParameterDescriptorImpl substituted = TypeParameterDescriptorImpl.createForFurtherModification(
newContainingDeclaration,
@@ -79,11 +79,15 @@ public class DescriptorSubstitutor {
mutableSubstitution.put(descriptor.getTypeConstructor(), new TypeProjection(substituted.getDefaultType()));
substitutedMap.put(descriptor, substituted);
result.add(substituted);
}
for (TypeParameterDescriptor descriptor : typeParameters) {
TypeParameterDescriptorImpl substituted = substitutedMap.get(descriptor);
for (JetType upperBound : descriptor.getUpperBounds()) {
substituted.getUpperBounds().add(substitutor.substitute(upperBound, Variance.INVARIANT));
}
result.add(substituted);
}
return substitutor;
@@ -4,7 +4,7 @@ fun foo<V : U, U>(<!UNUSED_PARAMETER!>v<!>: V, u: U) = u
fun bar<U, V : U>(<!UNUSED_PARAMETER!>v<!>: V, u: U) = u
fun test(a: Any, s: String) {
val <!UNUSED_VARIABLE!>b<!>: Any = <!TYPE_INFERENCE_UPPER_BOUND_VIOLATED!>foo<!>(a, s) //depends on type parameter order, will be fixed in next commit
val <!UNUSED_VARIABLE!>b<!>: Any = foo(a, s)
val <!UNUSED_VARIABLE!>c<!>: Any = bar(a, s)
}