
#11700: pattern match bug -------------------------------------+------------------------------------- Reporter: TobyGoodwin | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 7.10.3 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: | https://github.com/TobyGoodwin/odd- | ghc-pattern-bug Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by osa1): Hm, this is a weird one. I still don't understand the typechecker so can't fix this myself, but I did some debugging. Here's a simpler function that fails: {{{#!haskell fn2 :: Key User -> (Entity Message, Entity Folder) -> IO () fn2 usr cluster = let (Entity msgKey msg, Entity fldrKey fldr) = cluster in do print $ messageName msg print $ folderName fldr }}} Interestingly, the error message is about {{{Folder}}}, but if I replace {{{Message}}} with an empty tuple. {{{#!haskell fn2 :: Key User -> ((), Entity Folder) -> IO () fn2 usr cluster = let ((), Entity fldrKey fldr) = cluster in do print $ folderName fldr }}} It works. I also tried swapping the tuple elements: {{{#!haskell fn2 :: Key User -> (Entity Folder, Entity Message) -> IO () fn2 usr cluster = let (Entity fldrKey fldr, Entity msgKey msg) = cluster in do print $ messageName msg print $ folderName fldr }}} and it failed with an error message about {{{Message}}}: {{{ Message.hs:45:25: error: • Couldn't match expected type ‘Message’ with actual type ‘Message’ • In the first argument of ‘messageName’, namely ‘msg’ In the second argument of ‘($)’, namely ‘messageName msg’ In a stmt of a 'do' block: print $ messageName msg }}} It seems like some kind of side-effect is happening when type checking the first pattern. Oh, I also tried replacing the {{{in}}} part with {{{return ()}}}, and it worked: {{{#!haskell fn2 :: Key User -> (Entity Folder, Entity Message) -> IO () fn2 usr cluster = let (Entity fldrKey fldr, Entity msgKey msg) = cluster in do return () }}} -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/11700#comment:1 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler