Opened 12 years ago

Closed 10 years ago

#2006 closed bug (fixed)

unreachable GADT pattern clauses show up as warnings with -Wall

Reported by: ryani Owned by:
Priority: normal Milestone: 6.12 branch
Component: Compiler Version: 6.8.1
Keywords: Cc: ryani.spam@…, mnislaih@…, nicolas.pouillard@…
Operating System: Unknown/Multiple Architecture: Unknown/Multiple
Type of failure: None/Unknown Test Case:
Blocked By: Blocking:
Related Tickets: Differential Rev(s):
Wiki Page:

Description

In the following code, there is a line commented out. With it commented out, I get the following warning:

patternbug.hs:10:0:
    Warning: Pattern match(es) are non-exhaustive
	     In the definition of `interpret': Patterns not matched: EVar

With it uncommented, I get the following compiler error:

patternbug.hs:11:10:
    Inaccessible case alternative: Can't match types `()' and `(a, vs)'
    In the pattern: EVar
    In the definition of `interpret':
	interpret EVar = error "unreachable"

The exhaustive pattern-matching algorithm should ignore unreachable cases in its analysis.

{-# OPTIONS_GHC -Wall #-}
{-# LANGUAGE GADTs #-}
module PatternBug where

data Expr a vs where
    EPrim   :: String -> a -> Expr a vs
    EVar    :: Expr a (a,vs)

interpret :: Expr a () -> a
interpret (EPrim _ a) = a
-- interpret EVar = error "unreachable"

Change History (8)

comment:1 Changed 12 years ago by igloo

Milestone: 6.8 branch

Thanks for the report.

comment:2 Changed 12 years ago by simonpj

Milestone: 6.8 branch6.10 branch

Quite right. The "non-exhaustive pattern" warning comes from a part of the compiler that needs a serious overhaul. See #595. In particular, it's utterly unaware of GADTs, so it's going to produce spurious warnings, and will continue to do so until it is overhauled.

We definitely won't fix this on the 6.8 branch. Probably it needs a volunteer.

Simon

comment:3 Changed 11 years ago by mnislaih

Cc: mnislaih@… added

I am being annoyed by this too.

comment:4 Changed 11 years ago by ertai

Cc: nicolas.pouillard@… added

comment:5 Changed 11 years ago by simonmar

Architecture: UnknownUnknown/Multiple

comment:6 Changed 11 years ago by simonmar

Operating System: UnknownUnknown/Multiple

comment:7 Changed 10 years ago by igloo

Milestone: 6.10 branch6.12 branch

comment:8 Changed 10 years ago by igloo

Resolution: fixed
Status: newclosed

Fixed by:

Wed Jul 22 06:09:33 BST 2009  simonpj@microsoft.com
  * Take account of GADTs when reporting patterm-match overlap
Note: See TracTickets for help on using tickets.