Exemple #1
0
 public Type type(Env<String, Type> env) {
   Type t = op.type(env).deref(env);
   ast.types.Fun funType =
       Type.expect(op.getLineStart(), op.getLineEnd(), ast.types.Fun.class, this, t);
   checkArgTypes(funType, env);
   setType(funType.getRange());
   return getType();
 }
Exemple #2
0
 private void checkArgTypes(ast.types.Fun funType, Env<String, Type> env) {
   if (funType.getDomain().length == args.length) {
     for (int i = 0; i < funType.getDomain().length; i++) {
       Type suppliedType = args[i].type(env);
       Type expectedType = funType.getDomain()[i];
       if (!Type.equals(expectedType, suppliedType, env)) {
         throw new TypeMatchError(
             getLineStart(), getLineEnd(), suppliedType, Type.eval(expectedType, env));
       }
     }
   } else
     throw new TypeError(
         getLineStart(),
         getLineEnd(),
         "expecting " + funType.getDomain().length + " args but supplied with " + args.length);
 }