@@ -160,8 +160,10 @@ updateLHsType = traverse
161-- Main process
161-- Main process
162updateHsType :: HsType GhcPs -> (Any, HsType GhcPs)
162updateHsType :: HsType GhcPs -> (Any, HsType GhcPs)
163−updateHsType (HsQualTy xty ctxt body) =
163+updateHsType ty@(HsQualTy xty ctxt body) =
164+ if hasHasCallStack (unLoc ctxt)
164− flagASTModified $ HsQualTy xty (fmap appendHSC ctxt) body
166+ else flagASTModified $ HsQualTy xty (fmap appendHSC ctxt) body
165updateHsType ty@HsTyVar {} =
167updateHsType ty@HsTyVar {} =
166 flagASTModified $ HsQualTy xQualTy (noLoc $ appendHSC []) (noLoc ty)
168 flagASTModified $ HsQualTy xQualTy (noLoc $ appendHSC []) (noLoc ty)
167updateHsType ty@HsAppTy {} =
169updateHsType ty@HsAppTy {} =
@@ -188,6 +190,13 @@ flagASTModified a = (Any True, a)
188appendHSC :: HsContext GhcPs -> HsContext GhcPs
190appendHSC :: HsContext GhcPs -> HsContext GhcPs
189appendHSC cs = mkHSC : cs
191appendHSC cs = mkHSC : cs
193+hasHasCallStack :: HsContext GhcPs -> Bool
194+hasHasCallStack = any (checkHsType . unLoc)
196+ checkHsType :: HsType GhcPs -> Bool
197+ checkHsType (HsTyVar _ _ lid) = unLoc lid == (mkRdrUnqual $ mkClsOcc "HasCallStack")
198+ checkHsType _ = False
191-- make HasCallStack => constraint
200-- make HasCallStack => constraint
192mkHSC :: LHsType GhcPs
201mkHSC :: LHsType GhcPs
193mkHSC = noLoc $ HsTyVar xQualTy NotPromoted lId
202mkHSC = noLoc $ HsTyVar xQualTy NotPromoted lId