From ff01fad3cde7ce78286256a5b4360491b9b60673 Mon Sep 17 00:00:00 2001 From: Svetlana Isakova Date: Fri, 18 Jan 2013 17:47:04 +0400 Subject: [PATCH] substitute upper bounds after creating all substitutions for type parameters (otherwise it doesn't work for forward references) --- .../jet/lang/types/DescriptorSubstitutor.java | 10 +++++++--- .../upperBounds/useBoundsToInferTypeParamsSimple.kt | 2 +- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/types/DescriptorSubstitutor.java b/compiler/frontend/src/org/jetbrains/jet/lang/types/DescriptorSubstitutor.java index f1a9cf12f4f..7fb02d318f3 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/types/DescriptorSubstitutor.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/types/DescriptorSubstitutor.java @@ -66,7 +66,7 @@ public class DescriptorSubstitutor { return "DescriptorSubstitutor.substituteTypeParameters(" + mutableSubstitution + " / " + originalSubstitutor.getSubstitution() + ")"; } }); - + Map 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; diff --git a/compiler/testData/diagnostics/tests/inference/upperBounds/useBoundsToInferTypeParamsSimple.kt b/compiler/testData/diagnostics/tests/inference/upperBounds/useBoundsToInferTypeParamsSimple.kt index 2f57370b7b1..2a92270cfc7 100644 --- a/compiler/testData/diagnostics/tests/inference/upperBounds/useBoundsToInferTypeParamsSimple.kt +++ b/compiler/testData/diagnostics/tests/inference/upperBounds/useBoundsToInferTypeParamsSimple.kt @@ -4,7 +4,7 @@ fun foo(v: V, u: U) = u fun bar(v: V, u: U) = u fun test(a: Any, s: String) { - val b: Any = foo(a, s) //depends on type parameter order, will be fixed in next commit + val b: Any = foo(a, s) val c: Any = bar(a, s) }