emmalanguage/emma

[IR] Path dependent types

Closed this issue · 3 comments

Currently, the IR cannot deal with path dependent types, because it relies on transformations that decompose paths (ANF). That's why Type.fix always calls widen.

In Scala, a (stable) path is

  • either x where x is a stable identifier (i.e. val or object)
  • or p.x where p is a path and x is a stable identifier (member of the object p).

A path-dependent type can be one of:

  1. p.type where p is a path;
  2. p.T where T is a type member of the path p;
  3. p.T[A1, ..., An] where T is a polymorphic type member of the path p.

The problem with this is that a definition val x = y.z can have one of two types - y.z.type or the concrete type of z. In some contexts, the path-dependent type is better (e.g. instantiation of inner classes or method calls with dependent type signatures), in others the concrete type (e.g. arguments to a generic method, esp. if the result is some F[A] and not covariant).

Note that path dependent types are sometimes inferred (LHS of methods calls, arguments to method calls depending on the parameters, etc.)

It appears this was magically fixed by removing most .dealias.widen calls on types. I will add a test to ANFSpec that verifies the fix.

Ok it turns out that AlphaEq cannot handle path-dependent types 😞 Which is very logical, but that means I can't write such a test.

Resolved in #306