Skip to content

Fix warnings (that will be) introduced by ghc upgrade#397

Merged
MattSturgeon merged 1 commit into
NixOS:masterfrom
jfly:address-warnings-in-next-version-of-ghc
May 23, 2026
Merged

Fix warnings (that will be) introduced by ghc upgrade#397
MattSturgeon merged 1 commit into
NixOS:masterfrom
jfly:address-warnings-in-next-version-of-ghc

Conversation

@jfly
Copy link
Copy Markdown
Collaborator

@jfly jfly commented May 20, 2026

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 exapmle), 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
    |                                                                      ^^^^

@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 20, 2026

Nixpkgs diff

@jfly jfly force-pushed the address-warnings-in-next-version-of-ghc branch from 4a64836 to 20896fb Compare May 20, 2026 18:06
Copy link
Copy Markdown
Contributor

@MattSturgeon MattSturgeon left a comment

Choose a reason for hiding this comment

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

Seems reasonable to me. No objections.

I'll let someone more comfortable in Haskell approve, though. @dyegoaurelio are you able to review?

@dyegoaurelio dyegoaurelio force-pushed the address-warnings-in-next-version-of-ghc branch from 20896fb to 05fdbc4 Compare May 23, 2026 14:26
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>
@dyegoaurelio dyegoaurelio force-pushed the address-warnings-in-next-version-of-ghc branch from 05fdbc4 to 9f21550 Compare May 23, 2026 14:31
@MattSturgeon MattSturgeon merged commit 9354434 into NixOS:master May 23, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

3 participants