Opened 5 years ago

Last modified 11 months ago

#4139 new bug

Spurious non-exhaustive pattern match warnings are given using GADTs

Reported by: blarsen Owned by:
Priority: normal Milestone:
Component: Compiler Version: 7.4.1
Keywords: GADTs, warnings, pattern matching Cc: eir@…, hackage.haskell.org@…
Operating System: Unknown/Multiple Architecture: Unknown/Multiple
Type of failure: Incorrect warning at compile-time Test Case:
Blocked By: Blocking:
Related Tickets: #3927 Differential Revisions:

Description

When using slightly complicated GADTs, GHC gives me erroneous non-exhaustive pattern match warnings. I have attached an example. I have observed this behavior in the four versions of ghc that I tried (6.10.4, and 6.12.{1,2,3}).

Attachments (2)

GADTNonExhaustive.hs (1.4 KB) - added by blarsen 5 years ago.
A simple evaluator that demonstrates spurious non-exhaustive pattern match warnings
GADTbug.hs (369 bytes) - added by goldfire 3 years ago.
produces warning about non-exhaustive pattern match in GADT

Download all attachments as: .zip

Change History (10)

Changed 5 years ago by blarsen

A simple evaluator that demonstrates spurious non-exhaustive pattern match warnings

comment:1 Changed 5 years ago by igloo

  • Milestone set to 6.14.1
  • Owner set to simonpj

Thanks for the report.

See also #3927.

comment:2 follow-up: Changed 5 years ago by simonpj

  • Resolution set to invalid
  • Status changed from new to closed

Now I look at your example, I see that your claim isn't true! Consider

evalFst (Const (undefined :: Const (Int,Int))

That will hit the allegedly impossible alternative.

So in this case GHC is quite right. (The pattern match warnings are not all correct, but this one is, I think.)

Simon

comment:3 in reply to: ↑ 2 Changed 5 years ago by blarsen

Replying to simonpj:

Now I look at your example, I see that your claim isn't true! Consider

evalFst (Const (undefined :: Const (Int,Int))

That will hit the allegedly impossible alternative.

So in this case GHC is quite right. (The pattern match warnings are not all correct, but this one is, I think.)

Simon

Indeed! I had forgotten about undefined / bottom values.

Brad

comment:4 Changed 3 years ago by goldfire

  • Cc eir@… added
  • Owner simonpj deleted
  • Resolution invalid deleted
  • Status changed from closed to new
  • Type of failure changed from None/Unknown to Incorrect warning at compile-time
  • Version changed from 6.12.3 to 7.4.1

I have a case with the same bug description as above, but when I include the pattern suggested by the warning statement, I get a compiler error indicating unreachable code. I have attached my code.

Changed 3 years ago by goldfire

produces warning about non-exhaustive pattern match in GADT

comment:5 Changed 3 years ago by simonpj

  • difficulty set to Unknown

Good example. It has the same cause as #3927. Sorry no imminent cure. Needs someone to pay proper attention to it.

comment:6 Changed 3 years ago by goldfire

comment:7 Changed 2 years ago by liyang

  • Cc hackage.haskell.org@… added

comment:8 Changed 11 months ago by ezyang

  • Milestone 7.0.1 deleted
Note: See TracTickets for help on using tickets.