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

Add hints for type errors where the user might have meant {=} instead of {} #2238

Merged
merged 3 commits into from
Jul 7, 2021

Conversation

timbertson
Copy link
Collaborator

@timbertson timbertson commented Jul 1, 2021

I thought dhall-lang/dhall-lang#1024 would make for a good first use case of context-specific hints next to errors, much like rustc. The idea is that if you have a type error involving {}, and it's a context where {=} could work, we include a hint in the error output:

$ echo '{ x = 1 } // {}' | ./dist/build/Dhall/dhall

Use "dhall --explain" for detailed errors

Error: You can only override records

Hint: {} is the empty record type, use {=} for the empty record value

1│ { x = 1 } // {}

(input):1:1

This hint appears for the following type errors:

  • ({Type = { x: Natural }, default={ x = 1 }})::{}
  • {} // { x = 1 }
  • {} /\ { x = 1 }
  • (\(x: Natural) -> x + 1) {}

The hint is only shown when the erroneous value in question is literally {} so it should have a fairly high relevance. In the final example {=} would also be the wrong type though, so it's not 100%.

The only issue I had is when {} is on the right hand side of a combine operation, i.e. { x = 1 } /\ {}

The --explain text for this one actually looks incorrect to me, it ends in:

You supplied this expression as one of the arguments:

↳ { x = 1 }

... which is not a record, but is actually a:

↳ Type

My hint shows up when I reverse the operands, so it seems like maybe the code constructing this error is always passing in the left hand side, rather than the expression matching the non-record type.

sjakobi added a commit that referenced this pull request Jul 7, 2021
This bug manifested as an incorrect type error explanation:

    You supplied this expression as one of the arguments:

    ↳ { x = 1 }

    ... which is not a record, but is actually a:

    ↳ Type

    ────────────────────────────────────────────────────────────────────────────────

    1│ { x = 1 } /\ {}

This issue was reported in
#2238.
@sjakobi
Copy link
Collaborator

sjakobi commented Jul 7, 2021

@timbertson Thanks for the report of the incorrect type error explanation! I have created a fix in #2244.

Copy link
Collaborator

@sjakobi sjakobi left a comment

Choose a reason for hiding this comment

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

I like it! :)

dhall/src/Dhall/TypeCheck.hs Outdated Show resolved Hide resolved
dhall/src/Dhall/TypeCheck.hs Outdated Show resolved Hide resolved
dhall/src/Dhall/TypeCheck.hs Outdated Show resolved Hide resolved
dhall/src/Dhall/TypeCheck.hs Outdated Show resolved Hide resolved
sjakobi added a commit that referenced this pull request Jul 7, 2021
This bug manifested as an incorrect type error explanation:

    You supplied this expression as one of the arguments:

    ↳ { x = 1 }

    ... which is not a record, but is actually a:

    ↳ Type

    ────────────────────────────────────────────────────────────────────────────────

    1│ { x = 1 } /\ {}

This issue was reported in
#2238.
@sjakobi sjakobi requested a review from Gabriella439 July 7, 2021 12:08
Copy link
Collaborator

@Gabriella439 Gabriella439 left a comment

Choose a reason for hiding this comment

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

Thank you for doing this! 🙂

@Gabriella439 Gabriella439 merged commit 84b5ae8 into dhall-lang:master Jul 7, 2021
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