Fix handling of type families
parent
85359163cc
commit
b517eef71e
|
@ -1551,6 +1551,97 @@ instance Foo Int where
|
||||||
{ unBarInt :: Int
|
{ unBarInt :: Int
|
||||||
}
|
}
|
||||||
|
|
||||||
|
###############################################################################
|
||||||
|
###############################################################################
|
||||||
|
###############################################################################
|
||||||
|
#group gh-357
|
||||||
|
###############################################################################
|
||||||
|
###############################################################################
|
||||||
|
###############################################################################
|
||||||
|
|
||||||
|
#test type-instance-without-comment
|
||||||
|
|
||||||
|
{-# language TypeFamilies #-}
|
||||||
|
type family F a
|
||||||
|
type instance F Int = IO Int
|
||||||
|
|
||||||
|
#test type-instance-with-comment
|
||||||
|
|
||||||
|
{-# language TypeFamilies #-}
|
||||||
|
type family F a
|
||||||
|
type instance F Int = IO Int -- x
|
||||||
|
|
||||||
|
#test newtype-instance-without-comment
|
||||||
|
|
||||||
|
{-# language TypeFamilies #-}
|
||||||
|
data family F a
|
||||||
|
newtype instance F Int = N Int
|
||||||
|
|
||||||
|
#test newtype-instance-with-comment
|
||||||
|
|
||||||
|
{-# language TypeFamilies #-}
|
||||||
|
data family F a
|
||||||
|
newtype instance F Int = N Int -- x
|
||||||
|
|
||||||
|
#test data-instance-without-comment
|
||||||
|
|
||||||
|
{-# language TypeFamilies #-}
|
||||||
|
data family F a
|
||||||
|
data instance F Int = D Int
|
||||||
|
|
||||||
|
#test data-instance-with-comment
|
||||||
|
|
||||||
|
{-# language TypeFamilies #-}
|
||||||
|
data family F a
|
||||||
|
data instance F Int = D Int -- x
|
||||||
|
|
||||||
|
#test instance-type-without-comment
|
||||||
|
|
||||||
|
{-# language TypeFamilies #-}
|
||||||
|
class C a where
|
||||||
|
type family F a
|
||||||
|
instance C Int where
|
||||||
|
type F Int = IO Int
|
||||||
|
|
||||||
|
#test instance-type-with-comment
|
||||||
|
|
||||||
|
{-# language TypeFamilies #-}
|
||||||
|
class C a where
|
||||||
|
type family F a
|
||||||
|
instance C Int where
|
||||||
|
type F Int = IO Int -- x
|
||||||
|
|
||||||
|
#test instance-newtype-without-comment
|
||||||
|
|
||||||
|
{-# language TypeFamilies #-}
|
||||||
|
class C a where
|
||||||
|
data family F a
|
||||||
|
instance C Int where
|
||||||
|
newtype F Int = N Int
|
||||||
|
|
||||||
|
#test instance-newtype-with-comment
|
||||||
|
|
||||||
|
{-# language TypeFamilies #-}
|
||||||
|
class C a where
|
||||||
|
data family F a
|
||||||
|
instance C Int where
|
||||||
|
newtype F Int = N Int -- x
|
||||||
|
|
||||||
|
#test instance-data-without-comment
|
||||||
|
|
||||||
|
{-# language TypeFamilies #-}
|
||||||
|
class C a where
|
||||||
|
data family F a
|
||||||
|
instance C Int where
|
||||||
|
data F Int = D Int
|
||||||
|
|
||||||
|
#test instance-data-with-comment
|
||||||
|
|
||||||
|
{-# language TypeFamilies #-}
|
||||||
|
class C a where
|
||||||
|
data family F a
|
||||||
|
instance C Int where
|
||||||
|
data F Int = D Int -- x
|
||||||
|
|
||||||
###############################################################################
|
###############################################################################
|
||||||
###############################################################################
|
###############################################################################
|
||||||
|
|
|
@ -397,7 +397,7 @@ parsePrintModuleTests conf filename input = do
|
||||||
then return $ pPrintModule moduleConf perItemConf anns parsedModule
|
then return $ pPrintModule moduleConf perItemConf anns parsedModule
|
||||||
else lift
|
else lift
|
||||||
$ pPrintModuleAndCheck moduleConf perItemConf anns parsedModule
|
$ pPrintModuleAndCheck moduleConf perItemConf anns parsedModule
|
||||||
if null errs
|
if null $ filter (not . isErrorUnusedComment) errs
|
||||||
then pure $ TextL.toStrict $ ltext
|
then pure $ TextL.toStrict $ ltext
|
||||||
else
|
else
|
||||||
let
|
let
|
||||||
|
@ -410,6 +410,10 @@ parsePrintModuleTests conf filename input = do
|
||||||
ErrorOutputCheck -> "Output is not syntactically valid."
|
ErrorOutputCheck -> "Output is not syntactically valid."
|
||||||
in throwE $ "pretty printing error(s):\n" ++ List.unlines errStrs
|
in throwE $ "pretty printing error(s):\n" ++ List.unlines errStrs
|
||||||
|
|
||||||
|
isErrorUnusedComment :: BrittanyError -> Bool
|
||||||
|
isErrorUnusedComment x = case x of
|
||||||
|
ErrorUnusedComment _ -> True
|
||||||
|
_ -> False
|
||||||
|
|
||||||
-- this approach would for if there was a pure GHC.parseDynamicFilePragma.
|
-- this approach would for if there was a pure GHC.parseDynamicFilePragma.
|
||||||
-- Unfortunately that does not exist yet, so we cannot provide a nominally
|
-- Unfortunately that does not exist yet, so we cannot provide a nominally
|
||||||
|
@ -454,6 +458,7 @@ toLocal conf anns m = do
|
||||||
|
|
||||||
ppModule :: GenLocated SrcSpan HsModule -> PPM ()
|
ppModule :: GenLocated SrcSpan HsModule -> PPM ()
|
||||||
ppModule lmod@(L _loc _m@(HsModule _ _name _exports _ decls _ _)) = do
|
ppModule lmod@(L _loc _m@(HsModule _ _name _exports _ decls _ _)) = do
|
||||||
|
let annKey = ExactPrint.mkAnnKey lmod
|
||||||
post <- ppPreamble lmod
|
post <- ppPreamble lmod
|
||||||
decls `forM_` \decl -> do
|
decls `forM_` \decl -> do
|
||||||
let declAnnKey = ExactPrint.mkAnnKey decl
|
let declAnnKey = ExactPrint.mkAnnKey decl
|
||||||
|
@ -463,7 +468,9 @@ ppModule lmod@(L _loc _m@(HsModule _ _name _exports _ decls _ _)) = do
|
||||||
let mBindingConfs =
|
let mBindingConfs =
|
||||||
declBindingNames <&> \n -> Map.lookup n $ _icd_perBinding inlineConf
|
declBindingNames <&> \n -> Map.lookup n $ _icd_perBinding inlineConf
|
||||||
filteredAnns <- mAsk
|
filteredAnns <- mAsk
|
||||||
<&> \annMap -> Map.findWithDefault Map.empty declAnnKey annMap
|
<&> \annMap ->
|
||||||
|
Map.union (Map.findWithDefault Map.empty annKey annMap) $
|
||||||
|
Map.findWithDefault Map.empty declAnnKey annMap
|
||||||
|
|
||||||
traceIfDumpConf "bridoc annotations filtered/transformed"
|
traceIfDumpConf "bridoc annotations filtered/transformed"
|
||||||
_dconf_dump_annotations
|
_dconf_dump_annotations
|
||||||
|
|
Loading…
Reference in New Issue