-
Notifications
You must be signed in to change notification settings - Fork 40
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
GHC 9.8: Warnings about partial head
and tail
(-Wx-partial
)
#173
Comments
Can you use |
Sure. But I'd like standard warnings ( If I chose to opt into It would be better if I could switch a warning off on a finer level, e.g. just for one definition rather than for the whole file. (In this case, though, I wouldn't need that fine control.) |
Its a warning, not an error, so I think it's expected that in some cases the “fix” is telling the compiler they you know what you are doing (possibly by turning off the warning). Finer grained control would be nice indeed, for now we have it at the module level. |
Looking at the code in question: -- | On @template-haskell-2.11.0.0@ or later, if a 'GadtC' or 'RecGadtC' has
-- multiple 'Name's, the leftmost 'Name' will be chosen.
instance HasName Con where
name f (NormalC n tys) = (`NormalC` tys) <$> f n
name f (RecC n tys) = (`RecC` tys) <$> f n
name f (InfixC l n r) = (\n' -> InfixC l n' r) <$> f n
name f (ForallC bds ctx con) = ForallC bds ctx <$> name f con
#if MIN_VERSION_template_haskell(2,11,0)
name f (GadtC ns argTys retTy) =
(\n -> GadtC [n] argTys retTy) <$> f (head ns)
name f (RecGadtC ns argTys retTy) =
(\n -> RecGadtC [n] argTys retTy) <$> f (head ns)
#endif I suspect that this is a bug - the form of having multiple names would be: data GadtType where
GadtCon1, GadtCon2 :: Int -> CHar -> GadtType But this would collapse that into a single constructor. I do think you're guaranteed to have at least one case ns of
[] -> error "Provided an empty list of names in a GadtC, should never happen"
(n:_) -> n
-- or,
fromMaybe (error "Provided an empty list of names in a GadtC") $ listToMaybe ns These are fixes, since |
@parsonsmatt wrote:
Thanks @parsonsmatt, for this alert!, this should be investigated. Ping @stevenfontanella.
Yes it is safe here.
One should only use |
I think the larger issue is that
It looks like
That is one understanding. There are many ways to avoid using partial functions, and I gave a few other alternatives. In virtually all cases, I think writing But that's getting into the weeds on this specific case, where the real bug fix is to delete the instance, or warn on the instance, or introduce |
GHC 9.8 (alpha 1-3) reports new warnings with
-Wall
:These are not fixable because
template-haskell
does not use the non-empty list type in the definition of[Rec]GadtC
.There are two more warnings which looks that they could be fixed easily:
The text was updated successfully, but these errors were encountered: