Skip to content

Error message for cyclic type class#3381

Merged
natefaubion merged 5 commits intopurescript:masterfrom
saskliutas:master
Mar 26, 2019
Merged

Error message for cyclic type class#3381
natefaubion merged 5 commits intopurescript:masterfrom
saskliutas:master

Conversation

@saskliutas
Copy link
Copy Markdown
Contributor

@saskliutas saskliutas commented Jun 12, 2018

Made an attempt on #3223. Added check for cycles before desugaring type class declarations, now correct error message is shown.

Error message after changes:

A cycle appears in a set of type class definitions.
Cycles are disallowed because they can lead to loops in the type checker.

@hdgarrood
Copy link
Copy Markdown
Contributor

Thanks for the PR, and sorry this went so long unacknowledged! This looks good, but I think we can improve the error a little more still. We should be able to always include information about the names of the relevant classes, I think. Presumably if we get an SCC constructor with exactly one element in the list, that means we have a class which has itself as a superclass? In that case it might be best to print something like

A type class may not have itself as a superclass.

In the case where we have more than one class in the SCC, I think it would be better to print something like

A cycle appears in a set of type class definitions:
  {A, B, C}

where A, B, and C are the names of the classes appearing in the SCC constructor. I think ideally we'd be able to print an actual cycle like A -> B -> C -> A, but looking at the Data.Graph docs I think this might be a little more awkward to achieve so I think just printing the set of classes in a strongly-connected component should be fine.

If you're unlikely to pick this up again (which is totally understandable at this point) I'd appreciate it if you could let us know so that someone else can.

@saskliutas
Copy link
Copy Markdown
Contributor Author

@hdgarrood Thanks for your response. I have made changes as you suggested.

Copy link
Copy Markdown
Contributor

@hdgarrood hdgarrood left a comment

Choose a reason for hiding this comment

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

Looks good - just one more thing I've noticed and then I think this is good to merge. Also could you please add yourself to CONTRIBUTORS.md?

Copy link
Copy Markdown
Contributor

@hdgarrood hdgarrood left a comment

Choose a reason for hiding this comment

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

Thanks! The CI failure on AppVeyor isn't anything to do with your code, and it's passing on Travis, so I think we can just ignore it for now.

@natefaubion natefaubion merged commit b83fb18 into purescript:master Mar 26, 2019
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