Skip to content

Wingman: case split on punned record fields #1739

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 17, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions plugins/hls-tactics-plugin/src/Wingman/CaseSplit.hs
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,17 @@ wildifyT (S.map occNameString -> used) = everywhere $ mkT $ \case
------------------------------------------------------------------------------
-- | Replace a 'VarPat' with the given @'Pat' GhcPs@.
rewriteVarPat :: Data a => RdrName -> Pat GhcPs -> a -> a
rewriteVarPat name rep = everywhere $ mkT $ \case
VarPat _ (L _ var) | eqRdrName name var -> rep
(x :: Pat GhcPs) -> x
rewriteVarPat name rep = everywhere $
mkT (\case
VarPat _ (L _ var) | eqRdrName name var -> rep
(x :: Pat GhcPs) -> x
)
`extT` \case
HsRecField lbl _ True
| eqRdrName name $ unLoc $ rdrNameFieldOcc $ unLoc lbl
-> HsRecField lbl (toPatCompat rep) False
(x :: HsRecField' (FieldOcc GhcPs) (PatCompat GhcPs)) -> x



------------------------------------------------------------------------------
Expand Down
1 change: 1 addition & 0 deletions plugins/hls-tactics-plugin/test/CodeAction/DestructSpec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ spec = do
destructTest "gadt" 7 17 "GoldenGADTDestruct.hs"
destructTest "gadt" 8 17 "GoldenGADTDestructCoercion.hs"
destructTest "a" 7 25 "SplitPattern.hs"
destructTest "a" 6 18 "DestructPun.hs"

describe "layout" $ do
destructTest "b" 4 3 "LayoutBind.hs"
Expand Down
7 changes: 7 additions & 0 deletions plugins/hls-tactics-plugin/test/golden/DestructPun.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{-# LANGUAGE NamedFieldPuns #-}


data Foo = Foo { a :: Bool, b :: Bool }

foo Foo {a, b} = _

Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{-# LANGUAGE NamedFieldPuns #-}


data Foo = Foo { a :: Bool, b :: Bool }

foo Foo {a = False, b} = _
foo Foo {a = True, b} = _