josefs / Gradualizer

A Gradual type system for Erlang
MIT License
613 stars 35 forks source link

Unify type errors for patterns #142

Open Zalastax opened 5 years ago

Zalastax commented 5 years ago

As part of the effort of solving #49, #137 touched the error reporting for {var, _, _}. As @zuiderkwast writes, the error for expressions should not be the same as the error for patterns (we can't provide a good error description if they are the same).

What we need to happen:

josefs commented 5 years ago

What about an extra field in the error which indicated whether it comes from an expression or a pattern? Or do you have some alternative design in mind? It'd be good to have a concrete proposal to discuss.

Zalastax commented 5 years ago

@josefs I'll need to do some investigation to answer but my initial feeling is that it should be okay to do as you suggest. This issue basically served as a reminder.

I want the type for returned errors to be very precise so using a boolean had me scared initially. However, for the expressions which can't be patterns, we can eventually refine the type to only allow for false in those cases.

Stay tuned!

zuiderkwast commented 5 years ago

A while ago, I suggested this structure (though perhaps not exactly these atoms): {pattern_type_error, Pattern, ActualType, ExpectedType}, while for expressions keeping the current one {type_error, Expr, ActualType, ExpectedType}. How about that?

Perhaps there are other kinds of pattern type errors too, are there?