From 423180427464746458b7ed50a9f9c6c1439b408e Mon Sep 17 00:00:00 2001 From: Sandy Maguire Date: Fri, 18 Feb 2022 00:26:28 -0800 Subject: [PATCH] Don't use keywords for variable names --- .../hls-tactics-plugin/src/Wingman/Naming.hs | 24 ++++++++++++++++++- .../test/CodeAction/DestructSpec.hs | 1 + .../test/golden/DestructInt.expected.hs | 7 ++++++ .../test/golden/DestructInt.hs | 7 ++++++ 4 files changed, 38 insertions(+), 1 deletion(-) create mode 100644 plugins/hls-tactics-plugin/test/golden/DestructInt.expected.hs create mode 100644 plugins/hls-tactics-plugin/test/golden/DestructInt.hs diff --git a/plugins/hls-tactics-plugin/src/Wingman/Naming.hs b/plugins/hls-tactics-plugin/src/Wingman/Naming.hs index ab0c0e23d9..832fa117e1 100644 --- a/plugins/hls-tactics-plugin/src/Wingman/Naming.hs +++ b/plugins/hls-tactics-plugin/src/Wingman/Naming.hs @@ -220,7 +220,29 @@ mkGoodName in_scope (mkTyName -> tn) . foldMap (\n -> bool (pure n) mempty $ check n) $ tn <> fmap (<> "'") tn where - check n = S.member (mkVarOcc n) in_scope + check n = S.member (mkVarOcc n) $ illegalNames <> in_scope + + +illegalNames :: Set OccName +illegalNames = S.fromList $ fmap mkVarOcc + [ "case" + , "of" + , "class" + , "data" + , "do" + , "type" + , "if" + , "then" + , "else" + , "let" + , "in" + , "mdo" + , "newtype" + , "proc" + , "rec" + , "where" + ] + ------------------------------------------------------------------------------ diff --git a/plugins/hls-tactics-plugin/test/CodeAction/DestructSpec.hs b/plugins/hls-tactics-plugin/test/CodeAction/DestructSpec.hs index d0f76db01c..2251abfeb2 100644 --- a/plugins/hls-tactics-plugin/test/CodeAction/DestructSpec.hs +++ b/plugins/hls-tactics-plugin/test/CodeAction/DestructSpec.hs @@ -20,6 +20,7 @@ spec = do destructTest "b" 7 10 "DestructTyFam" destructTest "b" 7 10 "DestructDataFam" destructTest "b" 17 10 "DestructTyToDataFam" + destructTest "t" 6 10 "DestructInt" describe "layout" $ do destructTest "b" 4 3 "LayoutBind" diff --git a/plugins/hls-tactics-plugin/test/golden/DestructInt.expected.hs b/plugins/hls-tactics-plugin/test/golden/DestructInt.expected.hs new file mode 100644 index 0000000000..0f14deef83 --- /dev/null +++ b/plugins/hls-tactics-plugin/test/golden/DestructInt.expected.hs @@ -0,0 +1,7 @@ +import Data.Int + +data Test = Test Int32 + +test :: Test -> Int32 +test (Test in') = _w0 + diff --git a/plugins/hls-tactics-plugin/test/golden/DestructInt.hs b/plugins/hls-tactics-plugin/test/golden/DestructInt.hs new file mode 100644 index 0000000000..432a6d4074 --- /dev/null +++ b/plugins/hls-tactics-plugin/test/golden/DestructInt.hs @@ -0,0 +1,7 @@ +import Data.Int + +data Test = Test Int32 + +test :: Test -> Int32 +test t = _ +