Stream: ideas

Topic: Preferentially constrain types based on defintions even wit


view this post on Zulip Eli Dowling (Jan 03 2024 at 00:22):

Currently roc doesn't do a very good job of typechecking code that contains type errors. This is an issue for editor tooling because it stops us from knowing what types things are and so hover docs and completion doesn't work.
For example:

MyRec : { field1 : U8, field2 : Str }

add : MyRec -> MyRec
add = \var ->
    var + 1

If i hover over the type of var it says <type mismatch> despite us having an annotation, I would expect the compiler to still know that var is type MyRec because even though there is a type error later the annotation "locks" it as that type.

How feasible is this idea?

view this post on Zulip Ayaz Hafiz (Jan 03 2024 at 00:37):

It should be pretty easy to implement. I’m happy to point you to where the implementation changes need to be made if you’re interested.

view this post on Zulip Eli Dowling (Jan 03 2024 at 00:52):

Good to hear it's feasible. I'll put it on the backburner for now, and come back to it once I have some more time. It's not dire and I'd rather spend my time getting the rest of completion working for now.

But if you can outline what needs to be done, I'll get to it at some point :)

view this post on Zulip Ayaz Hafiz (Jan 03 2024 at 05:57):

There’s an Error type in the Subs structure, and the error type needs to store one (or both) versions of the type that produced the mismatch.

view this post on Zulip Eli Dowling (Jan 03 2024 at 22:02):

Okay So I've had a preliminary look at this:
It seems like i need to update that subs error type to store mismatch errors,
update the mismatch type and mismatch macro in unify.rs to save information about the types that contributed to the mismatch,
update the language server to read the information from Error types and allow field name completion using the highest precedence type within the list of conflicts
Update the hover response to show all the types we think a variable could be again showing them with some indication of precedence.


Last updated: Jun 16 2026 at 16:19 UTC