Skip to content

Commit

Permalink
Add a future test for #24862
Browse files Browse the repository at this point in the history
  • Loading branch information
alanz committed May 23, 2024
1 parent cd324ad commit 285d5b5
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 6 deletions.
3 changes: 2 additions & 1 deletion configure.sh
Original file line number Diff line number Diff line change
Expand Up @@ -242,5 +242,6 @@ rm -fr dist*
# cabal configure -fdev --enable-tests --with-compiler=ghc-9.10.1
# cabal configure -fdev --enable-tests --with-compiler=ghc-9.101 --allow-newer
# cabal configure -fdev -froundtrip --enable-tests --with-compiler=ghc-9.10.1
cabal configure -froundtrip --enable-tests --with-compiler=ghc-9.10.1
# cabal configure -froundtrip --enable-tests --with-compiler=ghc-9.10.1
cabal configure -fdev -froundtrip --enable-tests --with-compiler=ghc-9.10.1

41 changes: 36 additions & 5 deletions tests/Test/Transform.hs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import Test.HUnit
transformTestsTT :: LibDir -> Test
transformTestsTT libdir = TestLabel "transformTestsTT" $ TestList
[
mkTestModChange libdir changeWhereIn3b "WhereIn3b.hs"
mkTestModChange libdir addArg1 "AddArg1.hs"
]

transformTests :: LibDir -> Test
Expand Down Expand Up @@ -304,6 +304,8 @@ transformHighLevelTests libdir =
, mkTestModChange libdir addHiding2 "AddHiding2.hs"

, mkTestModChange libdir cloneDecl1 "CloneDecl1.hs"

, mkTestModChange libdir addArg1 "AddArg1.hs"
]

-- ---------------------------------------------------------------------
Expand Down Expand Up @@ -467,10 +469,10 @@ rmDecl2 _libdir lp = do
rmDecl3 :: Changer
rmDecl3 _libdir lp = do
let
doRmDecl = replaceDecls lp [de1',sd1,d2]
doRmDecl = replaceDecls lp [de1',sd1'',d2]
where
[de1,d2] = hsDecls lp
(de1',Just sd1) = modifyValD (getLocA de1) de1 $ \_m [sd1] ->
(de1',Just sd1'') = modifyValD (getLocA de1) de1 $ \_m [sd1] ->
let
sd1' = setEntryDP sd1 (DifferentLine 2 0)
in ([],Just sd1')
Expand All @@ -483,10 +485,10 @@ rmDecl3 _libdir lp = do
rmDecl4 :: Changer
rmDecl4 _libdir lp = do
let
doRmDecl = replaceDecls (anchorEof lp) [de1',sd1]
doRmDecl = replaceDecls (anchorEof lp) [de1',sd1'']
where
[de1] = hsDecls lp
(de1',Just sd1) = modifyValD (getLocA de1) de1 $ \_m [sd1,sd2] ->
(de1',Just sd1'') = modifyValD (getLocA de1) de1 $ \_m [sd1,sd2] ->
let
sd2' = transferEntryDP' sd1 sd2
sd1' = setEntryDP sd1 (DifferentLine 2 0)
Expand Down Expand Up @@ -649,3 +651,32 @@ cloneDecl1 _libdir lp = do
return lp'

-- ---------------------------------------------------------------------

addArg1 :: Changer
addArg1 _libdir lp = return $ replaceDecls lp [d']
where
-- GHC 9.10 has
-- noLocA = L (noAnnSrcSpan noSrcSpan)
-- noSrcSpan = UnhelpfulSpan UnhelpfulNoLocationInfo
--
-- instance (NoAnn ann) => NoAnn (EpAnn ann) where
-- noAnn = EpAnn noSpanAnchor noAnn emptyComments
-- noSpanAnchor :: (NoAnn a) => (EpaLocation' a)
-- noSpanAnchor = EpaDelta (SameLine 0) noAnn


unqualName = (mkRdrUnqual $ mkVarOcc "new_arg") :: IdP GhcPs
-- newPat = (L noAnnSrcSpanDP1 $ VarPat NoExtField (noLocA unqualName)) :: LPat GhcPs
newPat = (L noAnnSrcSpanDP1 $ VarPat NoExtField (L noAnn unqualName)) :: LPat GhcPs

[(L l (ValD xd funbind))] = hsDecls lp
FunBind x n (MG mgx (L lmm [L lm m])) = funbind
Match mx c pats grhs = m
pats' = pats ++ [newPat]
-- GRHSs gc [L gl (GRHS ga gg rhs)] binds = grhs
d' = (L l (ValD xd (FunBind x n (MG mgx (L lmm [L lm (Match mx c pats' grhs)])))))
-- d' = error $ "addArg1:" ++ showAst ga



-- ---------------------------------------------------------------------
4 changes: 4 additions & 0 deletions tests/examples/transform/AddArg1.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module AddArg1 where

-- When #24862 is fixed, the space should move automatically
foo x = new_def
4 changes: 4 additions & 0 deletions tests/examples/transform/AddArg1.hs.expected
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module AddArg1 where

-- When #24862 is fixed, the space should move automatically
foo x new_arg= new_def

0 comments on commit 285d5b5

Please sign in to comment.