Skip to content
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

Export action on type family exports with constructors (Tyfam(..)) #2635

Closed
googleson78 opened this issue Jan 24, 2022 · 3 comments · Fixed by #2643
Closed

Export action on type family exports with constructors (Tyfam(..)) #2635

googleson78 opened this issue Jan 24, 2022 · 3 comments · Fixed by #2643
Labels
component: ghcide level: easy The issue is suited for beginners type: bug Something isn't right: doesn't work as intended, documentation is missing/outdated, etc..

Comments

@googleson78
Copy link
Contributor

Your environment

HLS version:
1.5.1
Which OS do you use:
Debian
Which LSP client (editor/plugin) do you use:
LanguageClient-neovim

resolver: nightly-2021-09-12

Steps to reproduce

Add a file with a type family, with an empty export list. Use the "export definition" action on the type family. HLS generates an export with exported constructors, even though type families don't have constructors.

Expected behaviour

An export without constructors.

Actual behaviour

An export with constructors, which don't exist, causing an additional warning.

@googleson78 googleson78 added status: needs triage type: bug Something isn't right: doesn't work as intended, documentation is missing/outdated, etc.. labels Jan 24, 2022
@drsooch
Copy link
Collaborator

drsooch commented Jan 26, 2022

printExport :: ExportsAs -> T.Text -> T.Text
printExport ExportName x = parenthesizeIfNeeds False x
printExport ExportPattern x = "pattern " <> x
printExport ExportAll x = parenthesizeIfNeeds True x <> "(..)"
isTopLevel :: Range -> Bool
isTopLevel l = (_character . _start) l == 0
exportsAs :: HsDecl GhcPs -> Maybe (ExportsAs, Located (IdP GhcPs))
exportsAs (ValD _ FunBind {fun_id}) = Just (ExportName, reLoc fun_id)
exportsAs (ValD _ (PatSynBind _ PSB {psb_id})) = Just (ExportPattern, reLoc psb_id)
exportsAs (TyClD _ SynDecl{tcdLName}) = Just (ExportName, reLoc tcdLName)
exportsAs (TyClD _ DataDecl{tcdLName}) = Just (ExportAll, reLoc tcdLName)
exportsAs (TyClD _ ClassDecl{tcdLName}) = Just (ExportAll, reLoc tcdLName)
exportsAs (TyClD _ FamDecl{tcdFam}) = Just (ExportAll, reLoc $ fdLName tcdFam)
exportsAs _ = Nothing

Looks like type families default to having (..). Even the test in ghcide/test/exe/Main.hs expects there to be (..).

@drsooch
Copy link
Collaborator

drsooch commented Jan 26, 2022

That being said I tested quickly myself and I was able to export a TypeFamily with (..) with ghc generated no errors on compile. This was on 8.10.7 not sure if it's something new.

@drsooch drsooch added the level: easy The issue is suited for beginners label Jan 26, 2022
@googleson78
Copy link
Contributor Author

It triggers a warning, I believe this one - https://downloads.haskell.org/ghc/latest/docs/html/users_guide/using-warnings.html#ghc-flag--Wdodgy-exports

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component: ghcide level: easy The issue is suited for beginners type: bug Something isn't right: doesn't work as intended, documentation is missing/outdated, etc..
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants