Add testcase for #11224
[ghc.git] / testsuite / tests / patsyn / should_run / T11224.hs
1 {-# LANGUAGE PatternSynonyms , ViewPatterns #-}
2
3 -- inlining a pattern synonym shouldn't change semantics
4
5 import Text.Read
6
7 -- pattern PRead :: () => Read a => a -> String
8 pattern PRead a <- (readMaybe -> Just a)
9
10 foo :: String -> Int
11 foo (PRead x) = (x::Int)
12 foo (PRead xs) = sum (xs::[Int])
13 foo _ = 666
14
15 bar :: String -> Int
16 bar (readMaybe -> Just x) = (x::Int)
17 bar (readMaybe -> Just xs) = sum (xs::[Int])
18 bar _ = 666
19
20 main :: IO ()
21 main = do
22 print $ foo "1" -- 1
23 print $ foo "[1,2,3]" -- 666 -- ???
24 print $ foo "xxx" -- 666
25
26 print $ bar "1" -- 1
27 print $ bar "[1,2,3]" -- 6
28 print $ bar "xxx" -- 666