Skip to content

Commit

Permalink
Merge pull request #96 from zliu41/eta
Browse files Browse the repository at this point in the history
Set annSortKey properly for eta-reduce with local binds
  • Loading branch information
zliu41 authored Nov 14, 2020
2 parents a5d2c53 + c6be486 commit 7e4270e
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/Refact/Internal.hs
Original file line number Diff line number Diff line change
Expand Up @@ -454,8 +454,12 @@ doGenReplacement m p new old
in fromMaybe oldAnns $ do
oldAnn <- snd <$> find po oldAnns'
annWhere <- find ((== G GHC.AnnWhere) . fst) (annsDP oldAnn)
let newSortKey = fmap (setSrcSpanFile newFile) <$> annSortKey oldAnn
newKey <- fst <$> find pn oldAnns'
pure $ Map.adjust (\ann -> ann {annsDP = annsDP ann ++ [annWhere]}) newKey oldAnns
pure $ Map.adjust
(\ann -> ann {annsDP = annsDP ann ++ [annWhere], annSortKey = newSortKey})
newKey
oldAnns

-- Expand the SrcSpan of the "GRHS" entry in the new file to include the local binds
expandGRHSLoc = \case
Expand Down
4 changes: 4 additions & 0 deletions tests/examples/EtaReduceLocalTypeSig.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
f :: String -> String
f x = show x
where y :: String
y = "foo"
4 changes: 4 additions & 0 deletions tests/examples/EtaReduceLocalTypeSig.hs.expected
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
f :: String -> String
f = show
where y :: String
y = "foo"
1 change: 1 addition & 0 deletions tests/examples/EtaReduceLocalTypeSig.hs.refact
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[("test/examples/EtaReduceLocalTypeSig.hs:2:1-12: Warning: Eta reduce\nFound:\n f x = show x\nPerhaps:\n f = show\n",[Replace {rtype = Decl, pos = SrcSpan {startLine = 2, startCol = 1, endLine = 2, endCol = 13}, subts = [("body",SrcSpan {startLine = 2, startCol = 7, endLine = 2, endCol = 11})], orig = "f = body"}])]

0 comments on commit 7e4270e

Please sign in to comment.