package ilog.language.design.types;

/**
 * @version     Last modified on Thu Aug 22 13:47:12 2002 by hak
 * @author      <a href="mailto:hak@ilog.fr">Hassan A&iuml;t-Kaci</a>
 * @copyright   &copy; 2001 <a href="http://www.ilog.fr/">ILOG, S.A.</a>
 */

import ilog.language.util.Locatable;
import ilog.language.design.kernel.Expression;

/**
 * A <tt>CollectionBaseTypeGoal</tt> encapsulates a pair consisting of a collection expression
 * and a type. Such a goal is <i>proven</i> in the context of a <tt>TypeChecker</tt> by unifying
 * the type with the expression's collection type's base type.
 */

public class CollectionBaseTypeGoal extends BaseTypeGoal
{
  public CollectionBaseTypeGoal (Expression expression, Type type)
    {
      super(expression,type);
    }


  final void prove (TypeChecker typeChecker) throws FailedUnificationException
    {
      typeChecker.trail(this);
      //typeChecker.debugProve(this);

      Type collectionType = _expression.type();

      if (!(collectionType instanceof Collection))
        typeChecker.error(new BadCollectionTypeException(collectionType));

      collectionType.baseType().unify(_type,typeChecker);
    }
}
