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

x-partial warnings with GHC 9.8 #92

Open
andreasabel opened this issue Oct 7, 2023 · 2 comments
Open

x-partial warnings with GHC 9.8 #92

andreasabel opened this issue Oct 7, 2023 · 2 comments

Comments

@andreasabel
Copy link

There is a new warning x-partial (by default on) in GHC 9.8 that complains about head and tail:

Building library for tagsoup-0.14.8...

src/Text/HTML/TagSoup/Match.hs:197:4: warning: [GHC-63394] [-Wx-partial]
    In the use of ‘head’
    (imported from Prelude, but defined in GHC.List):
    "This is a partial function, it throws an error on empty lists. Use pattern matching or Data.List.uncons instead. Consider refactoring to use Data.List.NonEmpty."
    |
197 |    head . sections (tagOpenLit name pAttrs)
    |    ^^^^

src/Text/HTML/TagSoup/Match.hs:198:36: warning: [GHC-63394] [-Wx-partial]
    In the use of ‘head’
    (imported from Prelude, but defined in GHC.List):
    "This is a partial function, it throws an error on empty lists. Use pattern matching or Data.List.uncons instead. Consider refactoring to use Data.List.NonEmpty."
    |
198 |     where sections p = filter (p . head) . init . tails
    |                                    ^^^^

src/Text/HTML/TagSoup/Implementation.hs:51:48: warning: [GHC-63394] [-Wx-partial]
    In the use of ‘head’
    (imported from Prelude, but defined in GHC.List):
    "This is a partial function, it throws an error on empty lists. Use pattern matching or Data.List.uncons instead. Consider refactoring to use Data.List.NonEmpty."
   |
51 |                  ,tl = expand (positionChar p (head text)) (tail text)
   |                                                ^^^^

src/Text/HTML/TagSoup/Implementation.hs:51:61: warning: [GHC-63394] [-Wx-partial]
    In the use of ‘tail’
    (imported from Prelude, but defined in GHC.List):
    "This is a partial function, it throws an error on empty lists. Replace it with drop 1, or use pattern matching or Data.List.uncons instead. Consider refactoring to use Data.List.NonEmpty."
   |
51 |                  ,tl = expand (positionChar p (head text)) (tail text)
   |                                                             ^^^^

src/Text/HTML/TagSoup/Implementation.hs:52:52: warning: [GHC-63394] [-Wx-partial]
    In the use of ‘head’
    (imported from Prelude, but defined in GHC.List):
    "This is a partial function, it throws an error on empty lists. Use pattern matching or Data.List.uncons instead. Consider refactoring to use Data.List.NonEmpty."
   |
52 |                  ,hd = if null text then '\0' else head text
   |                                                    ^^^^

src/Text/HTML/TagSoup/Implementation.hs:146:46: warning: [GHC-63394] [-Wx-partial]
    In the use of ‘head’
    (imported from Prelude, but defined in GHC.List):
    "This is a partial function, it throws an error on empty lists. Use pattern matching or Data.List.uncons instead. Consider refactoring to use Data.List.NonEmpty."
    |
146 |               | isEntityHex x = chr_ $ fst $ head $ readHex s
    |                                              ^^^^

src/Text/HTML/TagSoup.hs:110:26: warning: [GHC-63394] [-Wx-partial]
    In the use of ‘head’
    (imported from Prelude, but defined in GHC.List):
    "This is a partial function, it throws an error on empty lists. Use pattern matching or Data.List.uncons instead. Consider refactoring to use Data.List.NonEmpty."
    |
110 | sections p = filter (p . head) . init . tails
    |                          ^^^^
@ndmitchell
Copy link
Owner

This is just a warning, so I think the right thing to do is ignore it. This code is safe, but the work to remove the use of head is tricky and potentially breaks more things. If someone else wants to do so, I wouldn't object.

@andreasabel
Copy link
Author

Water on my mills! https://gitlab.haskell.org/ghc/ghc/-/issues/23934

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

No branches or pull requests

2 participants