Skip to content

EmptyCase produces incorrect SrcSpans

If you compile the following program, you'll get a warning for f with an improperly placed SrcSpan:

{-# LANGUAGE EmptyCase #-}
{-# LANGUAGE TypeOperators #-}
{-# OPTIONS_GHC -Wincomplete-patterns #-}
module Bug where

import Data.Type.Equality

can'tHappen :: Int :~: Bool
can'tHappen = undefined

f, g :: Bool -> Bool
f True = case can'tHappen of {}
g True = case () of () -> True
$ /opt/ghc/8.4.2/bin/ghci Bug.hs
GHCi, version 8.4.2: http://www.haskell.org/ghc/  :? for help
Loaded GHCi configuration from /home/rgscott/.ghci
[1 of 1] Compiling Bug              ( Bug.hs, interpreted )

Bug.hs:12:1: warning: [-Wincomplete-patterns]
    Pattern match(es) are non-exhaustive
    In an equation for ‘f’: Patterns not matched: False
   |
12 | f True = case can'tHappen of {}
   | ^^^^^^^^^^^^^

Bug.hs:13:1: warning: [-Wincomplete-patterns]
    Pattern match(es) are non-exhaustive
    In an equation for ‘g’: Patterns not matched: False
   |
13 | g True = case () of () -> True
   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Ok, one module loaded.

Compare that to the warning for g, whose SrcSpan spans the entire clause, as expected.

The bug lies in the parser—patch incoming.

Trac metadata
Trac field Value
Version 8.4.2
Type Bug
TypeOfFailure OtherFailure
Priority normal
Resolution Unresolved
Component Compiler (Parser)
Test case
Differential revisions
BlockedBy
Related
Blocking
CC
Operating system
Architecture
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information