Indicate expected versus actual types in type errors · Issue #3399 · purescript/purescript · GitHub
Skip to content

Indicate expected versus actual types in type errors #3399

Open

Description

@i-am-the-slime

I never know what the compiler wants from me when it says:

Could not match type A with type B

Which one does it expect? Which one is the one I supply?
For people like me it's not always obvious which type I am supplying.
I don't really see any downside to changing this to:

Could not match expected type A with actual type B

I don't know about any tooling that might depend on this exact message.

Activity

  1. i-am-the-slime commented on Jul 10, 2018

    @i-am-the-slime
    ContributorAuthor

    I think it could be even nicer if the compiler could insert a little (?helpme (thingOfTheWrongType)) and suggest possible fixes but that's most probably out of scope.

  2. garyb commented on Jul 10, 2018

    @garyb
    Member

    We've had issues about this previously, and did attempt to change the error to work this way... but unfortunately the type checker isn't able to know for sure whether A or B is the type that is actually desired.

  3. hdgarrood commented on Jul 11, 2018

    @hdgarrood
    Contributor

    Yeah, I’m certain there is already an issue for exactly this, possibly even open.

  4. i-am-the-slime commented on Jul 12, 2018

    @i-am-the-slime
    ContributorAuthor

    I see. Sorry guys!

  5. i-am-the-slime commented on Jul 12, 2018

    @i-am-the-slime
    ContributorAuthor

    Actually maybe we could make that explicit in the message? I remember trying to find the order by making some minimal example. Since there is no order this could be misleading. I know there is nothing in the message suggests that there is an order but still. The message could have a little "in no particular order" disclaimer.

  6. hdgarrood commented on Jul 13, 2018

    @hdgarrood
    Contributor

    Previously: #3111 #1577 #1583

  7. hdgarrood commented on Jul 13, 2018

    @hdgarrood
    Contributor

    Actually sorry, I take back what I said before: while we do have discussion which notes that identifying expected vs actual types would be useful, there doesn’t appear to be an open issue for actually doing so.

  8. hdgarrood commented on Jul 13, 2018

    @hdgarrood
    Contributor

    So we might want to reopen this perhaps?

  9. JordanMartinez commented on Nov 27, 2018

    @JordanMartinez
    Contributor

    I think this should be reopened. At the very least, it would track that the issue does exist.

  10. changed the title [-]Improve error message for non-matching types[/-] [+]Indicate expected versus actual types in type errors[/+] on Jul 25, 2019
  11. ajnsit commented on Aug 19, 2021

    @ajnsit

    I wrote this on discord, but thought I would add it as a suggestion here as well -

    Looking at the error message in this issue #1577 - Some very useful information is partly present but buried - "checking that expression 4 has type String". Is it possible to put that information up front?

    For example the error messages could say something like -

    Error occurred while checking that
    expression
        4
      has type
        String
    
    Could not match type
        Int
      with type
        String
    while trying to match type Int
      with type String
    
    in value declaration foo
    
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions