on master help sign in
Fix the issue with promoted containers with promoted elements
commita392aef71e53cf63d54c372f68f3a8422f82db97 authorUtku Demir <me@utdemir.com> dateWed 14 Aug 2019, 17:25 (7 years ago) parent57373e5
3 files changed+36−3
data/examples/declaration/type/promotion-out.hs+12 data/examples/declaration/type/promotion.hs+8 src/Ormolu/Printer/Meat/Type.hs+16−3
data/examples/declaration/type/promotion-out.hs+12
@@ -5,3 +5,15 @@ data T = T' | T'T
55type S0 = ' T'
66
77type S1 = ' T'T
8+
9+type S2 = Proxy ('[ '[], '[]])
10+
11+type S4 = Proxy ('( 'Just, ' T'T))
12+
13+type S5 = Proxy ('[ 'Just, 'TT'T])
14+
15+type S6 = Proxy ('( '(), '()))
16+
17+type S7 = Proxy ('( 'a, 'b))
18+
19+type S8 = Proxy ('[Int, Bool])
data/examples/declaration/type/promotion.hs+8
@@ -5,3 +5,11 @@ data T = T' | T'T
55type S0 = ' T'
66
77type S1 = ' T'T
8+
9+type S2 = Proxy ( '[ '[], '[] ])
10+type S4 = Proxy ( '( 'Just, ' T'T))
11+type S5 = Proxy ( '[ 'Just, ' TT'T])
12+type S6 = Proxy ( '( '(), '() ))
13+type S7 = Proxy ( '( 'a, 'b ))
14+type S8 = Proxy ( '[ Int, Bool ])
15+
src/Ormolu/Printer/Meat/Type.hs+16−3
@@ -115,16 +115,29 @@ p_hsType = \case
115115 Promoted -> txt "'"
116116 NotPromoted -> return ()
117117 brackets $ do
118− case xs of
119− ((L _ (HsTyVar _ Promoted _)):_) -> space
118+ -- If both this list itself and the first element is promoted,
119+ -- we need to put a space in between or it fails to parse.
120+ case (p, xs) of
121+ (Promoted, ((L _ t):_)) | isPromoted t -> space
120122 _ -> return ()
121123 sitcc $ sep (comma >> breakpoint) (sitcc . located' p_hsType) xs
122124 HsExplicitTupleTy NoExt xs -> do
123125 txt "'"
124− parens $ sep (comma >> breakpoint) (located' p_hsType) xs
126+ parens $ do
127+ case xs of
128+ ((L _ t):_) | isPromoted t -> space
129+ _ -> return ()
130+ sep (comma >> breakpoint) (located' p_hsType) xs
125131 HsTyLit NoExt t -> atom t
126132 HsWildCardTy NoExt -> txt "_"
127133 XHsType (NHsCoreTy t) -> atom t
134+ where
135+ isPromoted = \case
136+ HsTyVar _ Promoted _ -> True
137+ HsExplicitListTy _ _ _ -> True
138+ HsExplicitTupleTy _ _ -> True
139+ _ -> False
140+
128141
129142p_hsContext :: HsContext GhcPs -> R ()
130143p_hsContext = \case