Type Inference is Causing Verification Error

Ming-Yee Iu mingyeeiu+lambda at gmail.com
Fri Sep 3 17:42:26 PDT 2010


Actually, it seems like my code doesn't type correctly, but the type
inferencer is not finding the problem and just outputs incorrect code.

Here is a simpler test case:

public class Test2
{
public static class Pair<U,V> {
  public Pair(U a, V b) {}
}
public static class DBSet2<T>  {
  public static interface Select<U, V> {
     public V select(DBSet2<U> val);
  }
  public static interface AggregateGroup<W, U, V> {
     public V aggregateSelect(W key, DBSet2<U> val);
  }
  public <U, V> DBSet2<Pair<U, V>> group(Select<T, U> select,
AggregateGroup<U, T, V> aggregate)
{return new DBSet2<Pair<U,V>>();}
}


  public static DBSet2<String> dummyReturn()
  {
    return null;
  }
  public static void main(String [] args)
  {
    DBSet2<Pair<Integer, Integer>> matches =
    dummyReturn()
      .group(#(ol) {return 5;},
                   #(key, olset){new Pair<Integer, Integer>(key, 7)}
                  );
  }
}


The type inferencer seems to be getting the type from the "matches"
variable even though that does not unify with what's returned by
group(). The return type of group() based on the provided methods
should be DBSet2<Pair<Integer, Pair<Integer,Integer>>> which does not
unify with DBSet2<Pair<Integer, Integer>>, so the code should fail to
compile.

-Ming


More information about the lambda-dev mailing list