package ilog.language.design.types;

/**
 * @version     Last modified on Mon Oct 07 09:43:03 2002 by hak
 * @author      <a href="mailto:hak@ilog.fr">Hassan A&iuml;t-Kaci</a>
 * @copyright   &copy; 2000-2002 <a href="http://www.ilog.fr/">ILOG, S.A.</a>
 */

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

/**
 * A <tt>CheckExitableGoal</tt> unifies the return type of the latest scope typechecker's
 * stack of exitable scopes with its own exit value type.
 */

public class CheckExitableGoal extends Goal
{
  private Type _type;
  private Locatable _extent;

  public CheckExitableGoal (Type type, Locatable extent)
    {
      _type = type;
      _extent = extent;
    }

  final Type type ()
    {
      return _type.value();
    }

  final Locatable extent ()
    {
      return _extent;
    }

  final void prove (TypeChecker typeChecker) throws TypingErrorException
    {
      trail(typeChecker);
      Scope scope = typeChecker.checkExitable(_extent);
      new FunctionType(scope.arity(),_type).setNoCurrying().unify(scope.typeRef(),typeChecker);
    }

  public final String toString ()
    {
      return super.toString() +
             ": (check exitable) return type => " + type() +
             ", extent => " + _extent;
    }
}
