From c9fef98b8d79ad60551d02eb71223363da188097 Mon Sep 17 00:00:00 2001 From: Svetlana Isakova Date: Wed, 11 Jul 2012 18:48:38 +0400 Subject: [PATCH] added assert that constraining type doesn't contain type variables --- .../inference/ConstraintsSystemImpl.java | 39 ++++++++++++------- 1 file changed, 26 insertions(+), 13 deletions(-) diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/inference/ConstraintsSystemImpl.java b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/inference/ConstraintsSystemImpl.java index 4eec087690c..972f3268f02 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/inference/ConstraintsSystemImpl.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/inference/ConstraintsSystemImpl.java @@ -136,21 +136,16 @@ public class ConstraintsSystemImpl implements ConstraintsSystem { DeclarationDescriptor subjectTypeDescriptor = subjectType.getConstructor().getDeclarationDescriptor(); if (subjectTypeDescriptor instanceof TypeParameterDescriptor) { - if (TypeUtils.dependsOnTypeParameterConstructors(constrainingType, Collections.singleton(DONT_CARE.getConstructor()))) return; - if (subjectType.isNullable()) { - constrainingType = TypeUtils.makeNotNullable(constrainingType); - } TypeParameterDescriptor typeParameter = (TypeParameterDescriptor) subjectTypeDescriptor; - if (constraintKind == ConstraintKind.SUPER_TYPE) { - typeParameterConstraints.get(typeParameter).addLowerBound(constrainingType); + TypeConstraintsImpl typeConstraints = typeParameterConstraints.get(typeParameter); + if (typeConstraints != null) { + addBoundToTypeConstraints(constraintKind, subjectType, constrainingType, typeConstraints); + return; } - else if (constraintKind == ConstraintKind.SUB_TYPE) { - typeParameterConstraints.get(typeParameter).addUpperBound(constrainingType); - } - else { - typeParameterConstraints.get(typeParameter).addExactBound(constrainingType); - } - return; + } + if (constrainingTypeDescriptor instanceof TypeParameterDescriptor) { + // assert that constraining type doesn't contain type variables + assert typeParameterConstraints.get(constrainingTypeDescriptor) == null; } if (constrainingTypeDescriptor instanceof ClassDescriptor && subjectTypeDescriptor instanceof ClassDescriptor) { @@ -190,6 +185,24 @@ public class ConstraintsSystemImpl implements ConstraintsSystem { errorConstraintPositions.add(constraintPosition); } + private void addBoundToTypeConstraints(@NotNull ConstraintKind constraintKind, @NotNull JetType subjectType, + @NotNull JetType constrainingType, @NotNull TypeConstraintsImpl typeConstraints) { + + if (TypeUtils.dependsOnTypeParameterConstructors(constrainingType, Collections.singleton(DONT_CARE.getConstructor()))) return; + if (subjectType.isNullable()) { + constrainingType = TypeUtils.makeNotNullable(constrainingType); + } + if (constraintKind == ConstraintKind.SUPER_TYPE) { + typeConstraints.addLowerBound(constrainingType); + } + else if (constraintKind == ConstraintKind.SUB_TYPE) { + typeConstraints.addUpperBound(constrainingType); + } + else { + typeConstraints.addExactBound(constrainingType); + } + } + @NotNull @Override public Set getTypeVariables() {