Skip to content

Commit

Permalink
Fix exporting operator pattern synonym (#4420)
Browse files Browse the repository at this point in the history
* Add tests for export unused top binding code action

For symbolic pattern synonyms, type families and type classes

* Parenthesize symbolic pattern synonyms in add export code action

* Refactor printExport

* Remove superfluous tests

* Revert implementation to correct one
  • Loading branch information
pbrinkmeier authored Oct 12, 2024
1 parent ae341fe commit da403a7
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -769,7 +769,7 @@ suggestExportUnusedTopBinding srcOpt ParsedModule{pm_parsed_source = L _ HsModul

printExport :: ExportsAs -> T.Text -> T.Text
printExport ExportName x = parenthesizeIfNeeds False x
printExport ExportPattern x = "pattern " <> x
printExport ExportPattern x = "pattern " <> parenthesizeIfNeeds False x
printExport ExportFamily x = parenthesizeIfNeeds True x
printExport ExportAll x = parenthesizeIfNeeds True x <> "(..)"

Expand Down
13 changes: 13 additions & 0 deletions plugins/hls-refactor-plugin/test/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -3413,6 +3413,19 @@ exportUnusedTests = testGroup "export unused actions"
, "module A (pattern Foo) where"
, "pattern Foo a <- (a, _)"
]
, testSession "unused pattern synonym operator" $ template
[ "{-# OPTIONS_GHC -Wunused-top-binds #-}"
, "{-# LANGUAGE PatternSynonyms #-}"
, "module A () where"
, "pattern x :+ y = (x, y)"
]
(R 3 0 3 12)
"Export ‘:+’"
[ "{-# OPTIONS_GHC -Wunused-top-binds #-}"
, "{-# LANGUAGE PatternSynonyms #-}"
, "module A (pattern (:+)) where"
, "pattern x :+ y = (x, y)"
]
, testSession "unused data type" $ template
[ "{-# OPTIONS_GHC -Wunused-top-binds #-}"
, "module A () where"
Expand Down

0 comments on commit da403a7

Please sign in to comment.