Fix warnings (that will be) introduced by ghc upgrade#397
Merged
MattSturgeon merged 1 commit intoMay 23, 2026
Merged
Conversation
4a64836 to
20896fb
Compare
Contributor
MattSturgeon
left a comment
There was a problem hiding this comment.
Seems reasonable to me. No objections.
I'll let someone more comfortable in Haskell approve, though. @dyegoaurelio are you able to review?
20896fb to
05fdbc4
Compare
We're upgrading to GHC 9.10.3, and it will start to emit warnings about
risky use of partial functions.
AFAICT, the old code wasn't wrong (we were always checking for empty
list before trying to call `head` on it, for example), but it's nice
when a compiler can check things for us!
```
$ cabal build
...
src/Nixfmt/Types.hs:375:68: warning: [GHC-63394] [-Wx-partial]
In the use of ‘head’
(imported from Prelude, but defined in GHC.Internal.List):
"This is a partial function, it throws an error on empty lists. Use pattern matching, 'Data.List.uncons' or 'Data.Maybe.listToMaybe' instead. Consider refactoring to use "Data.List.NonEmpty"."
|
375 | (List _ items _) | Prelude.length (unItems items) == 1 -> case Prelude.head (unItems items) of
| ^^^^^^^^^^^^
src/Nixfmt/Types.hs:384:69: warning: [GHC-63394] [-Wx-partial]
In the use of ‘head’
(imported from Prelude, but defined in GHC.Internal.List):
"This is a partial function, it throws an error on empty lists. Use pattern matching, 'Data.List.uncons' or 'Data.Maybe.listToMaybe' instead. Consider refactoring to use "Data.List.NonEmpty"."
|
384 | (Set _ _ items _) | Prelude.length (unItems items) == 1 -> case Prelude.head (unItems items) of
| ^^^^^^^^^^^^
[3 of 8] Compiling Nixfmt.Predoc ( src/Nixfmt/Predoc.hs, dist-newstyle/build/x86_64-linux/ghc-9.10.3/nixfmt-1.2.0/build/Nixfmt/Predoc.o, dist-newstyle/build/x86_64-linux/ghc-9.10.3/nixfmt-1.2.0/build/Nixfmt/Predoc.dyn_o )
src/Nixfmt/Predoc.hs:169:35: warning: [GHC-63394] [-Wx-partial]
In the use of ‘head’
(imported from Prelude, but defined in GHC.Internal.List):
"This is a partial function, it throws an error on empty lists. Use pattern matching, 'Data.List.uncons' or 'Data.Maybe.listToMaybe' instead. Consider refactoring to use "Data.List.NonEmpty"."
|
169 | if p /= [] && (isSoftSpacing (head p) || isSoftSpacing (last p))
| ^^^^
src/Nixfmt/Predoc.hs:634:27: warning: [GHC-63394] [-Wx-partial]
In the use of ‘head’
(imported from Prelude, but defined in GHC.Internal.List):
"This is a partial function, it throws an error on empty lists. Use pattern matching, 'Data.List.uncons' or 'Data.Maybe.listToMaybe' instead. Consider refactoring to use "Data.List.NonEmpty"."
|
634 | grp' = case head grp of
| ^^^^
src/Nixfmt/Predoc.hs:635:30: warning: [GHC-63394] [-Wx-partial]
In the use of ‘tail’
(imported from Prelude, but defined in GHC.Internal.List):
"This is a partial function, it throws an error on empty lists. Replace it with 'drop' 1, or use pattern matching or 'GHC.Internal.Data.List.uncons' instead. Consider refactoring to use "Data.List.NonEmpty"."
|
635 | Spacing _ -> tail grp
| ^^^^
src/Nixfmt/Predoc.hs:636:70: warning: [GHC-63394] [-Wx-partial]
In the use of ‘tail’
(imported from Prelude, but defined in GHC.Internal.List):
"This is a partial function, it throws an error on empty lists. Replace it with 'drop' 1, or use pattern matching or 'GHC.Internal.Data.List.uncons' instead. Consider refactoring to use "Data.List.NonEmpty"."
|
636 | Group ann ((Spacing _) : inner) -> Group ann inner : tail grp
| ^^^^
```
Co-authored-by: Dyego Aurélio <dyegoaurelio@gmail.com>
05fdbc4 to
9f21550
Compare
dyegoaurelio
approved these changes
May 23, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
We're upgrading to GHC 9.10.3, and it will start to emit warnings about risky use of partial functions.
AFAICT, the old code wasn't wrong (we were always checking for empty list before trying to call
headon it, for exapmle), but it's nice when a compiler can check things for us!