@@ -141,6 +141,13 @@ dropHsParTy :: LHsType (GhcPass pass) -> LHsType (GhcPass pass)
141141dropHsParTy (L _ (HsParTy _ ty)) = ty
142142dropHsParTy other = other
143143
144+ normalizeConstraintDP :: [LocatedAn AnnListItem (HsType GhcPs )] -> [LocatedAn AnnListItem (HsType GhcPs )]
145+ normalizeConstraintDP [] = []
146+ normalizeConstraintDP xs = normalizeFirst xs
147+ where
148+ normalizeFirst (x: rest) = setEntryDP x (SameLine 0 ) : rest
149+ normalizeFirst [] = []
150+
144151removeConstraint ::
145152 -- | Predicate: Which context to drop.
146153 (LHsType GhcPs -> Bool ) ->
@@ -154,15 +161,13 @@ removeConstraint toRemove = go . traceAst "REMOVE_CONSTRAINT_input"
154161#else
155162 go (L l it@ HsQualTy {hst_ctxt = L l' ctxt, hst_body}) = Rewrite (locA l) $ \ _ -> do
156163#endif
157- let ctxt' = filter (not . toRemove) ctxt
158- removeStuff = (toRemove <$> headMaybe ctxt) == Just True
159- let hst_body' = if removeStuff then resetEntryDP hst_body else hst_body
164+ let ctxt' = normalizeConstraintDP $ filter (not . toRemove) ctxt
160165 return $ case ctxt' of
161- [] -> hst_body'
166+ [] -> hst_body
162167 _ -> do
163168 let ctxt'' = over _last (first removeComma) ctxt'
164169 L l $ it{ hst_ctxt = L l' ctxt''
165- , hst_body = hst_body'
170+ , hst_body = hst_body
166171 }
167172 go (L _ (HsParTy _ ty)) = go ty
168173 go (L _ HsForAllTy {hst_body}) = go hst_body
@@ -244,11 +249,6 @@ liftParseAST df s = case parseAST df "" s of
244249 Right x -> pure (makeDeltaAst x)
245250 Left _ -> TransformT $ lift $ Left $ " No parse: " <> s
246251
247-
248- headMaybe :: [a ] -> Maybe a
249- headMaybe [] = Nothing
250- headMaybe (a : _) = Just a
251-
252252lastMaybe :: [a ] -> Maybe a
253253lastMaybe [] = Nothing
254254lastMaybe other = Just $ last other
0 commit comments