on master help sign in
Fix rendering of certain record patterns
6bc7333mrkkrp
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
50 inci $ velt' (located' p_pat <$> xs)
50 inci $ velt' (located' p_pat <$> xs)
51 RecCon (HsRecFields fields dotdot) -> do
51 RecCon (HsRecFields fields dotdot) -> do
52 p_rdrName pat
52 p_rdrName pat
53− case dotdot of
53+ breakpoint
54+ let f = \case
54− Nothing -> txt " {..}"
55+ Nothing -> txt ".."
55− Just _ -> do
56+ Just x -> located x p_hsRecField
56− braces $ velt (withSep comma (located' p_hsRecField) fields)
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]
57 InfixCon x y -> do
62 InfixCon x y -> do
58 located x p_pat
63 located x p_pat
59 space
64 space
@@ -71,6 +76,10 @@ p_pat = \case
71 XPat NoExt -> notImplemented "XPat"
76 XPat NoExt -> notImplemented "XPat"
72
77
73p_hsRecField :: HsRecField' (FieldOcc GhcPs) (LPat GhcPs) -> R ()
78p_hsRecField :: HsRecField' (FieldOcc GhcPs) (LPat GhcPs) -> R ()
74−p_hsRecField HsRecField {..} =
79+p_hsRecField HsRecField {..} = do
75 located hsRecFieldLbl $ \x ->
80 located hsRecFieldLbl $ \x ->
76 p_rdrName (rdrNameFieldOcc x)
81 p_rdrName (rdrNameFieldOcc x)
82+ unless hsRecPun $ do
83+ txt " ="
84+ breakpoint
85+ inci (located hsRecFieldArg p_pat)