Opened 7 years ago

Closed 4 years ago

Last modified 19 months ago

#6124 closed bug (duplicate)

Spurious non-exhaustive warning with GADT and newtypes

Reported by: joeyadams Owned by:
Priority: normal Milestone: 8.0.1
Component: Compiler (Type checker) Version: 7.4.1
Keywords: PatternMatchWarnings Cc: bgamari@…
Operating System: Unknown/Multiple Architecture: Unknown/Multiple
Type of failure: Incorrect warning at compile-time Test Case:
Blocked By: Blocking:
Related Tickets: Differential Rev(s):
Wiki Page:


This may be related to #3927 or similar, but here's another case where the compiler produces a "Pattern match(es) are non-exhaustive" warning for patterns on a GADT that are impossible to implement:

newtype A = MkA Int
newtype B = MkB Char

data T a where
    A :: T A
    B :: T B

f :: T A -> A
f A = undefined

This produces the following warning:

    Warning: Pattern match(es) are non-exhaustive
             In an equation for `f': Patterns not matched: B

It is impossible to write a pattern for B because B :: T B does not match T A.

If I replace newtype with data for both A and B, the warning goes away. If I replace only one instance of either newtype, it will still produce the warning.

Change History (8)

comment:1 Changed 7 years ago by simonpj

difficulty: Unknown

Thanks. I'm afriad this is part of a collection of pattern-match-exhaustiveness-checking tickets: #595, #5728, #3927, #5724, #5762, #4139. I think it's precisely #3927 but have not checked carefully.

This whole area needs love, but it's not trivial or I'd have done it by now!


comment:2 Changed 7 years ago by igloo

Milestone: 7.8.1

comment:3 Changed 6 years ago by bgamari

Cc: bgamari@… added

comment:4 Changed 6 years ago by thoughtpolice


Moving to 7.10.1.

comment:5 Changed 5 years ago by thoughtpolice


Moving to 7.12.1 milestone; if you feel this is an error and should be addressed sooner, please move it back to the 7.10.1 milestone.

comment:6 Changed 4 years ago by thomie

Resolution: duplicate
Status: newclosed

Because the existence of duplicate tickets makes doing a BugSweep of the bug tracker more cumbersome, I'm closing these tickets as duplicate. Don't worry, they're still listed on PatternMatchCheck, and will hopefully all be addressed by the work on #595 ("Overhaul GHC's overlapping/non-exhaustive pattern checking").

comment:7 Changed 4 years ago by thoughtpolice


Milestone renamed

comment:8 Changed 19 months ago by simonpj

Keywords: PatternMatchWarnings added
Note: See TracTickets for help on using tickets.