Opened 3 years ago

Closed 3 years ago

#8952 closed bug (fixed)

Bang patterns don't work as the specification says

Reported by: dolio Owned by:
Priority: normal Milestone: 7.8.1
Component: Compiler Version: 7.6.3
Keywords: Cc:
Operating System: Unknown/Multiple Architecture: Unknown/Multiple
Type of failure: Incorrect result at runtime Test Case: deSugar/should_run/T8952
Blocked By: Blocking:
Related Tickets: Differential Rev(s):
Wiki Page:


In investigating the behavior of bang patterns for an implementation of my own, I came across a discrepancy between the specification and GHC's implementation. Here is an example:

case Nothing of
  !(~(Just x)) -> 5
  Nothing      -> 12

This evaluates to 12. In other words, !(~p) is equivalent to p. However, the bang patterns description says that this should be equivalent to:

Nothing `seq` case Nothing of
  ~(Just x) -> 5
  Nothing   -> 12

which evaluates to 5. So, one of either the description or the implementation must be incorrect. In fact, GHC is even a bit confused, as it issues a warning about overlapping patterns for the bang pattern case statement, even though the successful branch is the 'unreachable' one.

The description makes more sense to me, but I'm not terribly invested in the behavior of this; it is admittedly a pretty obscure corner case.

Change History (4)

comment:1 Changed 3 years ago by simonpj

Dead right, thank you. Easy to fix. Patch coming.


comment:2 Changed 3 years ago by Simon Peyton Jones <simonpj@…>

In 3671d0027329804a31a628a5bee355e0640a2045/ghc:

Fix desguaring of bang patterns (Trac #8952)

A palpable bug, although one that will rarely bite

comment:3 Changed 3 years ago by simonpj

Status: newmerge
Test Case: deSugar/should_run/T8952

Merge only if convenient.


comment:4 Changed 3 years ago by thoughtpolice

Milestone: 7.8.1
Resolution: fixed
Status: mergeclosed

Merged, thanks!

Note: See TracTickets for help on using tickets.