From 8a4afb9330a35c665fd4ccbcc90e83182a8edc20 Mon Sep 17 00:00:00 2001 From: Svetlana Isakova Date: Thu, 26 Sep 2013 14:44:22 +0400 Subject: [PATCH] support one more special case of propagating bound constraints (temporary while there is no common constraint system and its resolution) --- .../inference/upperBounds/doNotInferFromBoundsOnly.kt | 4 ++-- .../resolve/calls/inference/ConstraintSystemImpl.java | 11 +++++++++++ 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/compiler/testData/diagnostics/tests/inference/upperBounds/doNotInferFromBoundsOnly.kt b/compiler/testData/diagnostics/tests/inference/upperBounds/doNotInferFromBoundsOnly.kt index 885438f26c9..a663002f8d0 100644 --- a/compiler/testData/diagnostics/tests/inference/upperBounds/doNotInferFromBoundsOnly.kt +++ b/compiler/testData/diagnostics/tests/inference/upperBounds/doNotInferFromBoundsOnly.kt @@ -55,7 +55,7 @@ fun test6(a: A) { fun emptyStrangeMap4(l: MutableList): Map = throw Exception("$l") fun test7(list: MutableList) { - emptyStrangeMap4(list) + emptyStrangeMap4(list) } //-------------- @@ -66,4 +66,4 @@ fun test7() : Map = emptyStrangeMap() fun foo(): U = throw Exception() -fun test8(): Int = foo() +fun test8(): Int = foo() diff --git a/core/descriptors/src/org/jetbrains/jet/lang/resolve/calls/inference/ConstraintSystemImpl.java b/core/descriptors/src/org/jetbrains/jet/lang/resolve/calls/inference/ConstraintSystemImpl.java index a30c386e7c7..0fc0511ab3c 100644 --- a/core/descriptors/src/org/jetbrains/jet/lang/resolve/calls/inference/ConstraintSystemImpl.java +++ b/core/descriptors/src/org/jetbrains/jet/lang/resolve/calls/inference/ConstraintSystemImpl.java @@ -437,6 +437,17 @@ public class ConstraintSystemImpl implements ConstraintSystem { addSubtypeConstraint(constraint.type, declaredUpperBound, position); } } + ClassifierDescriptor declarationDescriptor = declaredUpperBound.getConstructor().getDeclarationDescriptor(); + if (declarationDescriptor instanceof TypeParameterDescriptor && typeParameterConstraints.containsKey(declarationDescriptor)) { + TypeConstraintsImpl typeConstraintsForUpperBound = typeParameterConstraints.get(declarationDescriptor); + for (Constraint constraint : typeConstraintsForUpperBound.getConstraints()) { + if (constraint.boundKind == UPPER_BOUND || constraint.boundKind == EXACT_BOUND) { + ConstraintPosition position = ConstraintPosition.getCompoundConstraintPosition( + ConstraintPosition.getTypeBoundPosition(typeParameterDescriptor.getIndex()), constraint.constraintPosition); + typeConstraints.addConstraint(UPPER_BOUND, constraint.type, position); + } + } + } } } }