Skip to content

Commit 0d43d09

Browse files
authored
Don't use keywords for variable names (#2717)
1 parent 78305f2 commit 0d43d09

File tree

4 files changed

+38
-1
lines changed

4 files changed

+38
-1
lines changed

plugins/hls-tactics-plugin/src/Wingman/Naming.hs

+23-1
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,29 @@ mkGoodName in_scope (mkTyName -> tn)
220220
. foldMap (\n -> bool (pure n) mempty $ check n)
221221
$ tn <> fmap (<> "'") tn
222222
where
223-
check n = S.member (mkVarOcc n) in_scope
223+
check n = S.member (mkVarOcc n) $ illegalNames <> in_scope
224+
225+
226+
illegalNames :: Set OccName
227+
illegalNames = S.fromList $ fmap mkVarOcc
228+
[ "case"
229+
, "of"
230+
, "class"
231+
, "data"
232+
, "do"
233+
, "type"
234+
, "if"
235+
, "then"
236+
, "else"
237+
, "let"
238+
, "in"
239+
, "mdo"
240+
, "newtype"
241+
, "proc"
242+
, "rec"
243+
, "where"
244+
]
245+
224246

225247

226248
------------------------------------------------------------------------------

plugins/hls-tactics-plugin/test/CodeAction/DestructSpec.hs

+1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ spec = do
2020
destructTest "b" 7 10 "DestructTyFam"
2121
destructTest "b" 7 10 "DestructDataFam"
2222
destructTest "b" 17 10 "DestructTyToDataFam"
23+
destructTest "t" 6 10 "DestructInt"
2324

2425
describe "layout" $ do
2526
destructTest "b" 4 3 "LayoutBind"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import Data.Int
2+
3+
data Test = Test Int32
4+
5+
test :: Test -> Int32
6+
test (Test in') = _w0
7+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import Data.Int
2+
3+
data Test = Test Int32
4+
5+
test :: Test -> Int32
6+
test t = _
7+

0 commit comments

Comments
 (0)