dlist icon indicating copy to clipboard operation
dlist copied to clipboard

Tests have compilation warnings about partial functions with GHC 9.8

Open andreasabel opened this issue 2 years ago • 4 comments

tests/DListProperties.hs:70:31: warning: [GHC-63394] [-Wx-partial]
    In the use of ‘head’
    (imported from Data.List, 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."
   |
70 | prop_head = eqOn (not . null) List.head (head . fromList)
   |                               ^^^^^^^^^

tests/DListProperties.hs:73:31: warning: [GHC-63394] [-Wx-partial]
    In the use of ‘tail’
    (imported from Data.List, 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."
   |
73 | prop_tail = eqOn (not . null) List.tail (tail . fromList)
   |                               ^^^^^^^^^

It seems that the use of head and tail here is intended, so maybe just switch off the warning.

andreasabel avatar Aug 31 '23 19:08 andreasabel

Thanks! I couldn't find any documentation on -Wx-partial. How do I turn it off?

spl avatar Sep 01 '23 17:09 spl

Ah, I think I just found it: -Wno-x-partial

spl avatar Sep 01 '23 17:09 spl

If I understand the proposal correctly, it seems like -Wno-x-partial is not backwards-compatible, so it would need to be done for GHC >= 9.8 in DListProperties.hs. Is that correct?

spl avatar Sep 01 '23 18:09 spl

Indeed, yes.

andreasabel avatar Sep 02 '23 17:09 andreasabel