[GHC] #13484: Incorrect Exhaustivity Checking

#13484: Incorrect Exhaustivity Checking -------------------------------------+------------------------------------- Reporter: andrewthad | Owner: (none) Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 8.0.2 Keywords: | Operating System: Unknown/Multiple Architecture: | Type of failure: None/Unknown Unknown/Multiple | Test Case: | Blocked By: Blocking: | Related Tickets: Differential Rev(s): | Wiki Page: -------------------------------------+------------------------------------- Small example: {{{ {-# LANGUAGE KindSignatures #-} {-# LANGUAGE GADTs #-} {-# LANGUAGE TypeOperators #-} {-# LANGUAGE RankNTypes #-} {-# LANGUAGE PolyKinds #-} {-# LANGUAGE DataKinds #-} {-# OPTIONS_GHC -Werror -fwarn-incomplete-patterns #-} data Chunk (f :: k -> *) (xs :: [k]) where ChunkCons :: f a -> f b -> f c -> f d -> Chunk f xs -> Chunk f (a ': b ': c ': d ': xs) ChunkNil :: Chunk f '[] impossibleChunk01 :: Chunk f as -> Chunk f (a ': as) -> b impossibleChunk01 (ChunkCons _ _ _ _ c1) (ChunkCons _ _ _ _ c2) = impossibleChunk01 c1 c2 }}} This fails with: {{{ fast_records.hs:32:1: warning: [-Wincomplete-patterns] Pattern match(es) are non-exhaustive In an equation for ‘impossibleChunk01’: Patterns not matched: ChunkNil _ }}} Obviously a Chunk and a Chunk that's one element bigger cannot both exist. They must each be a multiple of 4. The impossibleChunk01 function is supposed to prove this. However, GHC doesn't currently figure out that neither data constructor can pair up with ChunkNil. This may be a moot point. The EmptyCase extension is currently sort of broken (because it currently never warns), but in GHC 8.2, it does some exhaustivity checking to ensure that you aren't shooting yourself in the foot. So, I might be able to write: {{{ impossibleChunk01 :: Chunk f as -> Chunk f (a ': as) -> b impossibleChunk01 (ChunkCons _ _ _ _ c1) (ChunkCons _ _ _ _ c2) = impossibleChunk01 c1 c2 impossibleChunk01 ChunkNill x = case x of {} }}} If that's the case (no pun intended), then I don't mind having to manually help out the exhaustivity checker in that way. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/13484 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#13484: Incorrect Exhaustivity Checking -------------------------------------+------------------------------------- Reporter: andrewthad | Owner: (none) Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 8.0.2 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by RyanGlScott): This is expected behavior. The first implementation of `impossibleChunk01` you gave is not exhaustive because the second argument might be `⊥`, which may involve neither constructor! If you don't believe me, try evaluating `impossibleChunk01 ChunkNil (let x = x in x)`. So the most correct solution is to adopt your suggestion and write this second case: {{{#!hs impossibleChunk01 ChunkNill x = case x of {} }}} And, as you noted, GHC 8.2 will verify that that empty-case on `x` really is exhaustive, so you can be assured that `x` isn't inhabited by a (terminating) `Chunk` value. Is that a satisfying answer? If so, please feel free to close this ticket. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/13484#comment:1 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#13484: Incorrect Exhaustivity Checking -------------------------------------+------------------------------------- Reporter: andrewthad | Owner: (none) Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 8.0.2 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by andrewthad): Thanks. That makes sense, and it addresses my concerns. Closing. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/13484#comment:2 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#13484: Incorrect Exhaustivity Checking -------------------------------------+------------------------------------- Reporter: andrewthad | Owner: (none) Type: bug | Status: closed Priority: normal | Milestone: Component: Compiler | Version: 8.0.2 Resolution: invalid | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Changes (by andrewthad): * status: new => closed * resolution: => invalid -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/13484#comment:3 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler
participants (1)
-
GHC