on master help sign in
Fix rendering of certain record patterns
commit6bc7333a6dfff472e4d226305ef6a970aff2d449 authormrkkrp <mark.karpov@tweag.io> dateWed 5 Jun 2019, 20:44 (7 years ago) parent1b287b3
3 files changed+51−5
data/examples/declaration/value/function/record-patterns-out.hs+19 data/examples/declaration/value/function/record-patterns.hs+18 src/Ormolu/Printer/Meat/Declaration/Pat.hs+14−5
data/examples/declaration/value/function/record-patterns-out.hsnew file+19
@@ -0,0 +1,19 @@
1+foo :: Boom -> Int
2+foo Boom {..} = 10
3+
4+bar0 :: Boom -> Int
5+bar0 Boom {boom} = boom
6+
7+bar1 :: Boom -> Int
8+bar1 Boom {boom = b} = b
9+
10+baz :: Boom -> Int
11+baz Boom {boom = b, ..} = b
12+
13+quux :: Boom -> Int
14+quux
15+ Boom
16+ { boom = a
17+ , foom = b
18+ , ..
19+ } = a + b
data/examples/declaration/value/function/record-patterns.hsnew file+18
@@ -0,0 +1,18 @@
1+foo :: Boom -> Int
2+foo Boom {..} = 10
3+
4+bar0 :: Boom -> Int
5+bar0 Boom {boom} = boom
6+
7+bar1 :: Boom -> Int
8+bar1 Boom { boom = b } = b
9+
10+baz :: Boom -> Int
11+baz Boom { boom = b, .. } = b
12+
13+quux :: Boom -> Int
14+quux Boom
15+ { boom = a
16+ , foom = b
17+ , ..
18+ } = a + b
src/Ormolu/Printer/Meat/Declaration/Pat.hs+14−5
@@ -50,10 +50,15 @@ p_pat = \case
5050 inci $ velt' (located' p_pat <$> xs)
5151 RecCon (HsRecFields fields dotdot) -> do
5252 p_rdrName pat
53− case dotdot of
54− Nothing -> txt " {..}"
55− Just _ -> do
56− braces $ velt (withSep comma (located' p_hsRecField) fields)
53+ breakpoint
54+ let f = \case
55+ Nothing -> txt ".."
56+ Just x -> located x p_hsRecField
57+ inci . braces . velt . withSep comma f $ case dotdot of
58+ Nothing ->
59+ Just <$> fields
60+ Just n -> do
61+ (Just <$> take n fields) ++ [Nothing]
5762 InfixCon x y -> do
5863 located x p_pat
5964 space
@@ -71,6 +76,10 @@ p_pat = \case
7176 XPat NoExt -> notImplemented "XPat"
7277
7378p_hsRecField :: HsRecField' (FieldOcc GhcPs) (LPat GhcPs) -> R ()
74−p_hsRecField HsRecField {..} =
79+p_hsRecField HsRecField {..} = do
7580 located hsRecFieldLbl $ \x ->
7681 p_rdrName (rdrNameFieldOcc x)
82+ unless hsRecPun $ do
83+ txt " ="
84+ breakpoint
85+ inci (located hsRecFieldArg p_pat)