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

Add {-# LANGUAGE Data #-} to the top of the file? (y or n) #1834

Closed
andreasabel opened this issue Jan 10, 2024 · 2 comments · Fixed by #1835
Closed

Add {-# LANGUAGE Data #-} to the top of the file? (y or n) #1834

andreasabel opened this issue Jan 10, 2024 · 2 comments · Fixed by #1835

Comments

@andreasabel
Copy link
Member

andreasabel commented Jan 10, 2024

When I load a hs file without project (cabal or stack) I get asked

Add {-# LANGUAGE Data #-} to the top of the file? (y or n)

This question can be repeated several times in a row, regardless whether I answer y or n.
Each time I answer y the {-# LANGUAGE Data #-} line will be added (which does not make any sense since LANGUAGE pragmas are idempotent).

The Data extension isn't even listed here: https://ghc.gitlab.haskell.org/ghc/doc/users_guide/exts/table.html
I don't know what purpose it should serve.

I just upgraded to the latest version of haskell-mode (v20231115) but the problem persists.

@andreasabel
Copy link
Member Author

Seems to be originating from here:

(when haskell-process-suggest-language-pragmas
(haskell-process-suggest-pragma
session
"LANGUAGE"
(match-string 1 msg)
file)))

It does not seem to limit suggestion to valid pragmas, the name of the pragma is here obtained by (match-string 1 msg), maybe coming from this match:
(or
(and (string-match " -X\\([A-Z][A-Za-z]+\\)" msg)
(not (string-match "\\([A-Z][A-Za-z]+\\) is deprecated" msg)))
(string-match "Use \\([A-Z][A-Za-z]+\\) to permit this" msg)
(string-match "Use \\([A-Z][A-Za-z]+\\) to allow" msg)
(string-match "Use \\([A-Z][A-Za-z]+\\) to enable" msg)
(string-match
"Use \\([A-Z][A-Za-z]+\\) if you want to disable this"
msg)
(string-match "use \\([A-Z][A-Za-z]+\\)" msg)
(string-match "You need \\([A-Z][A-Za-z]+\\)" msg)))

Ah, I guess this is thanks to our wonderful new x-partial warning:

In the *haskell* buffer I see:

Lect1.hs:111:13-16: warning: [GHC-63394] [-Wx-partial] …
In the use of ‘head’
(imported from Prelude, but defined in GHC.List):
"This is a partial function, it throws an error on empty lists. Use pattern matching or Data.List.uncons instead. Consider refactoring to use Data.List.NonEmpty."

Can you spot which regex matches here and extracts a Data hypothetical language extension?

andreasabel added a commit that referenced this issue Jan 10, 2024
… suggestion

Remove bad regex that was supposed to recognize a LANGUAGE suggestion.

This regex fires unfortunately on GHC 9.8's new `x-partial` warning,
destroying the UX with obnoxious questions whether to "add LANGUAGE Data".

Closes #1834.
@andreasabel
Copy link
Member Author

In PR #1834 this issue is fixed by removing the bad regex.

purcell added a commit that referenced this issue Jan 16, 2024
Fix #1834: remove bad regex that was supposed to recognize a LANGUAGE suggestion
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
1 participant