on master help sign in
Fix the issue with promoted containers with promoted elements
a392aefUtku Demir
data/examples/declaration/type/promotion-out.hs+12
@@ -5,3 +5,15 @@ data T = T' | T'T
5type S0 = ' T'
5type S0 = ' T'
6
6
7type S1 = ' T'T
7type 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
5type S0 = ' T'
5type S0 = ' T'
6
6
7type S1 = ' T'T
7type 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
115 Promoted -> txt "'"
115 Promoted -> txt "'"
116 NotPromoted -> return ()
116 NotPromoted -> return ()
117 brackets $ do
117 brackets $ do
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.
118− case xs of
120+ case (p, xs) of
119− ((L _ (HsTyVar _ Promoted _)):_) -> space
121+ (Promoted, ((L _ t):_)) | isPromoted t -> space
120 _ -> return ()
122 _ -> return ()
121 sitcc $ sep (comma >> breakpoint) (sitcc . located' p_hsType) xs
123 sitcc $ sep (comma >> breakpoint) (sitcc . located' p_hsType) xs
122 HsExplicitTupleTy NoExt xs -> do
124 HsExplicitTupleTy NoExt xs -> do
123 txt "'"
125 txt "'"
126+ parens $ do
127+ case xs of
128+ ((L _ t):_) | isPromoted t -> space
129+ _ -> return ()
124− parens $ sep (comma >> breakpoint) (located' p_hsType) xs
130+ sep (comma >> breakpoint) (located' p_hsType) xs
125 HsTyLit NoExt t -> atom t
131 HsTyLit NoExt t -> atom t
126 HsWildCardTy NoExt -> txt "_"
132 HsWildCardTy NoExt -> txt "_"
127 XHsType (NHsCoreTy t) -> atom t
133 XHsType (NHsCoreTy t) -> atom t
134+ where
135+ isPromoted = \case
136+ HsTyVar _ Promoted _ -> True
137+ HsExplicitListTy _ _ _ -> True
138+ HsExplicitTupleTy _ _ -> True
139+ _ -> False
140+
128
141
129p_hsContext :: HsContext GhcPs -> R ()
142p_hsContext :: HsContext GhcPs -> R ()
130p_hsContext = \case
143p_hsContext = \case