[GHC] #11224: Program doesn't preserve semantics after pattern synonym inlining.

GHC ghc-devs at haskell.org
Mon Dec 14 20:40:04 UTC 2015


#11224: Program doesn't preserve semantics after pattern synonym inlining.
-------------------------------------+-------------------------------------
           Reporter:  anton.dubovik  |             Owner:
               Type:  bug            |            Status:  new
           Priority:  normal         |         Milestone:
          Component:  Compiler       |           Version:  7.10.2
           Keywords:                 |  Operating System:  Windows
       Architecture:  x86_64         |   Type of failure:  Incorrect result
  (amd64)                            |  at runtime
          Test Case:                 |        Blocked By:
           Blocking:                 |   Related Tickets:
Differential Rev(s):                 |         Wiki Page:
-------------------------------------+-------------------------------------
 {{{#!hs
 {-# language
    PatternSynonyms
  , ViewPatterns
  #-}

 import Text.Read

 -- pattern PRead :: () => Read a => a -> String
 pattern PRead a <- (readMaybe -> Just a)

 foo :: String -> Int
 foo (PRead x)  = (x::Int)
 foo (PRead xs) = sum (xs::[Int])
 foo _ = 666

 bar :: String -> Int
 bar (readMaybe -> Just x)  = (x::Int)
 bar (readMaybe -> Just xs) = sum (xs::[Int])
 bar _ = 666

 main :: IO ()
 main = do
   print $ foo "1"       -- 1
   print $ foo "[1,2,3]" -- 666 -- ???
   print $ foo "xxx"     -- 666

   print $ bar "1"       -- 1
   print $ bar "[1,2,3]" -- 6
   print $ bar "xxx"     -- 666
 }}}

 I'm expecting that semantics of the function `foo` would not change if I
 inline pattern synonym.

 However it does. `bar` successfully matches string against list of ints,
 whereas `foo` apperently skips this pattern and fall back to the catch-all
 case.

 Reproducible both in GHCi and GHC.

--
Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/11224>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler


More information about the ghc-tickets mailing list