#14228 closed bug (fixed)
PatternSynonyms Non-exhaustive with UnboxedSums
Reported by: | guibou | Owned by: | |
---|---|---|---|
Priority: | normal | Milestone: | 8.2.2 |
Component: | Compiler | Version: | 8.2.1 |
Keywords: | UnboxedSums, PatternSynonyms | Cc: | |
Operating System: | Unknown/Multiple | Architecture: | Unknown/Multiple |
Type of failure: | Incorrect result at runtime | Test Case: | |
Blocked By: | Blocking: | ||
Related Tickets: | Differential Rev(s): | Phab:D3951 | |
Wiki Page: |
Description
The following implementation of Maybe
using UnboxedSums results in Non-exhaustive patterns in case
:
(Failure.hs
file)
{-# LANGUAGE UnboxedSums #-} {-# LANGUAGE PatternSynonyms #-} type Maybe' t = (# t | () #) pattern Just' :: a -> Maybe' a pattern Just' x = (# x | #) pattern Nothing' :: Maybe' a pattern Nothing' = (# | () #) foo x = case x of Nothing' -> putStrLn "nothing" Just' _ -> putStrLn "just" main = do putStrLn "Nothing'" foo Nothing' putStrLn "Just'" foo (Just' "hello")
When executed, it prints:
Nothing' nothing Just' Failure: Failure.hs:10:20-29: Non-exhaustive patterns in case
Compiled with ghc Failure.hs
.
Please note that by removing the pattern
s, and writting foo
as following works as expected:
foo x = case x of (# | () #) -> putStrLn "nothing" (# _ | #) -> putStrLn "just"
Change History (6)
comment:1 Changed 7 months ago by
Keywords: | UnboxedSums added; UnboxedSum removed |
---|
comment:2 Changed 7 months ago by
Differential Rev(s): | → Phab:D3951 |
---|---|
Milestone: | → 8.2.2 |
Status: | new → patch |
comment:4 Changed 7 months ago by
Status: | patch → merge |
---|
comment:5 Changed 7 months ago by
Resolution: | → fixed |
---|---|
Status: | merge → closed |
comment:6 Changed 7 months ago by
comment:3 merged to ghc-8.2
as fb5190185b6819ff4f4b64167d37da85337c524c.
Note: See
TracTickets for help on using
tickets.
Wow! Great catch.
Indeed, the
ddump-simpl
output for that program looks mighty suspicious. I'll post an abridged version below:Just look at that rubbish! The matchers for
Just'
andNothing'
each take a failure continuation as an argument, but appear to ignore them completely and just proceed directly topatError
in case the expected pattern wasn't matched.