PmCheck: Long-distance info and where clause "refactorings" are strange
Consider the following two programs:
{-# OPTIONS_GHC -Wincomplete-patterns -fforce-recomp #-}
module Lib where
f :: Maybe Int -> Int -> Int
f x y = case x of
Nothing -> 1
_ -> g y
where
g y = case x of
Just n -> n + y
{-# OPTIONS_GHC -Wincomplete-patterns -fforce-recomp #-}
module Lib where
f :: Maybe Int -> Int -> Int
f x y = case x of
Nothing -> 1
_ -> g y
where
g y = case x of
Just n -> n + y
The first warns that the case
match within g
is incomplete with GHC HEAD, the second doesn't.
It's a really delicate interaction between where
clause syntax and very accurate long-distance information, maybe even too accurate for its own good: The first program syntactically associates the where
clause with the FunDef of f
(I think), while the second one associates the where
clause with the _
case alt. In the latter case, we know that x
can't be Nothing
, but not so in the former case. Indeed, it's not unreasonable to call g
from the Nothing
case in the first program:
module Lib where
f :: Maybe Int -> Int -> Int
f x y = case x of
Nothing -> g 1
_ -> g y
where
g y = case x of
Just n -> n + y
And hence it's correct to warn there. I know Haskell is indentation-sensitive, but this kind of interaction was very surprising to me. I'll just open this issue for future reference, as I'm sure that I won't be the last person stumbling over this.