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

Fix non-exhaustive pattern match in dhall lint #780

Merged
merged 5 commits into from
Jan 17, 2019
Merged

Conversation

Gabriella439
Copy link
Collaborator

dhall lint would fail on the following expression:

    let replicate = https://prelude.dhall-lang.org/List/replicate

in  let Config = { name : Text, age : Natural }

in  let Configs = List Config

in  replicate 10 Text "!"

... because the code (incorrectly) assumed that simplifying an inner
let binding would preserve at least one let binding. However, when the
outer let (beginning with let replicate) is simplified the inner let
(beginning with let Config) simplifies down to just replicate 10 Text "!"
which has no let binding at all, leading to a pattern match failure.

This change fixes that by extending the code to correctly handle that case
with an exhaustive pattern match.

`dhall lint` would fail on the following expression:

```
    let replicate = https://prelude.dhall-lang.org/List/replicate

in  let Config = { name : Text, age : Natural }

in  let Configs = List Config

in  replicate 10 Text "!"
```

... because the code (incorrectly) assumed that simplifying an inner
`let` binding would preserve at least one `let` binding.  However, when the
outer `let` (beginning with `let replicate`) is simplified the inner `let`
(beginning with `let Config`) simplifies down to just `replicate 10 Text "!"`
which has no `let` binding at all, leading to a pattern match failure.

This change fixes that by extending the code to correctly handle that case
with an exhaustive pattern match.
@ocharles
Copy link
Member

ocharles commented Jan 15, 2019

Looks good, but how did this make it into master? Does this need -fwarn-incomplete-uni-patterns to trigger a warning? Or is this just not being built with -Wall -Werror?

@Gabriella439
Copy link
Collaborator Author

@ocharles: It is being built with -Wall -Werror. I was actually surprised that this sort of non-exhaustive pattern match wasn't a warning by default. I will test to see if -fwarn-incomplete-uni-patterns would have caught this

... as suggested by @ocharles to prevent this from recurring

I added an exception to the `Dhall` module since fixing those
non-exhaustive pattern matches requires more invasive changes
This is supposed to be only turned on for specific CI builds
@Gabriella439 Gabriella439 merged commit f24f665 into master Jan 17, 2019
@Gabriella439 Gabriella439 deleted the gabriel/fix_lint branch January 17, 2019 05:59
@joneshf
Copy link
Collaborator

joneshf commented Jan 31, 2019

I almost opened an issue to report this bug, but stumbled onto it by accident.

In case it helps future searches of this bug, the error is: src/Dhall/Lint.hs:67:9-51: Irrefutable pattern failed for pattern Let (l' :| ls') d'. Hopefully that will turn up in a GitHub search/suggestion for Related Issues and prevent duplicate reports.

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.

None yet

3 participants