[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
wherex
is a stable identifier (i.e.val
orobject
) - or
p.x
wherep
is a path andx
is a stable identifier (member of the objectp
).
A path-dependent type can be one of:
p.type
wherep
is a path;p.T
whereT
is a type member of the pathp
;p.T[A1, ..., An]
whereT
is a polymorphic type member of the pathp
.
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.