Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve unification error when it fails #9

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

shulhi
Copy link
Contributor

@shulhi shulhi commented Dec 23, 2022

  • Previously, this returns an empty list when no two types match.
  • Also, this handles returning error with dummy location when carried type errors are empty. Otherwise, when the carried type errors are empty, this function just returns an empty list instead of unification error.

@@ -381,7 +381,7 @@ inferTypeReps allTypeClasses (ForallTC tvs tyCls (ImplType _impl ty)) inputTys o
Left errs -> Left errs
Right subst ->
let tyClsSubst = Set.map (apply subst) tyCls
in case find (\(TypeClass nm _) -> nm == "rep") $ Set.toList tyClsSubst of
in case List.find (\(TypeClass nm _) -> nm == "rep") $ Set.toList tyClsSubst of
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmm not sure why i wasn't just using set find here?? probably not terribly important tho

Comment on lines +1161 to 1165
| List.null err =
let pos = initialPos ""
loc = (pos, pos)
in throwError [UnificationFail Set.empty (TTuple ts1) (TTuple ts2) loc]
| otherwise = throwError [UnificationFail (getTypeClassFromErrs err) (TTuple ts1) (TTuple ts2) loc | loc <- (getLocFromErrs err)]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking at this code, the error throwing doesn't really make sense. My original design is definitely wonky here. The idea behind throwing a list was to link several places in code which generate a contradiction. e.g. somewhere we assign a variable the value bool and elsewhere we try to add a number to it. the error should point to those two places in the code as a contradiction. However, I'm not sure this ever properly worked as intended. It seems we always just throw a singleton error anyway.

To get proper error location, we should probably track location for types we are unifying and then add those to the error when throwing, instead of adding a dummy pos. This will require a bit of a re-engineering tho.

Copy link
Contributor

@goodlyrottenapple goodlyrottenapple left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Think we should overhaul how position information is passed around to the unification function to not rely on dummy positions

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants