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

Internal Error ghcide-code-actions-imports-exports arising from usage of erroneous type constructor as a term due to incorrect import #3978

Closed
MathiasSven opened this issue Jan 17, 2024 · 4 comments
Labels
component: imports plugin type: bug Something isn't right: doesn't work as intended, documentation is missing/outdated, etc..

Comments

@MathiasSven
Copy link

The circumstances in which this is manifested seem strangely specific, I might have mistitled. Essentially, when you try to use a type constructor as a data constructor, to the right of an arrow which pattern matches on any constructor in curtain situations, and where a data constructor with the same name as the type constructor is within "adding an identifier to existing import" away from HLS, this error manifests. More details on rep.

Your environment

Which OS do you use?
Linux 6.7.0, NixOS, 24.05 (Uakari), 24.05.20240108.317484b

Which version of GHC do you use, and how did you install it?
Version 9.4.8, installed via nixpkgs

How is your project built (alternative: link to the project)?
N/A

Which LSP client (editor/plugin) do you use?
VS Codium+vscode-haskell

Which version of HLS do you use, and how did you install it?
haskell-language-server version: 2.4.0.0 (GHC: 9.4.8), nixpkgs

Have you configured HLS in any way (especially: a hie.yaml file)?
No

Steps to reproduce

module Bug where

import Data.Monoid (Sum)  -- Note only the type constructor is imported, the correct import would be (Sum(Sum))

f (Just a) = Sum

As the cursor finishes writing Sum (On VSCode at least), internal error pop-ups will start to show up, hovering over it as well.

Scenarios I have tested

in all these cases, there are normal errors, ❌ (triggered) or ✅ (didn't trigger) only concerns if it triggered an internal error

f a = Sum              --
f = Sum                --
f = (\x -> Sum)        --
f (Just a) = Sum       --
f (a, b) = Sum         --
f = (\(Just x) -> Sum) --
f = undefined . Sum    --
f = Sum . undefined    --
Explicit secondary module

Bug.hs

module Bug where

import BugBase (Foo)

f (Just a) = Foo

BugBase.hs:

module BugBase where

data Foo = Foo

The above BugBase.hs causes the internal error on Foo at Bug.hs, if BugBase.hs had:
data Foo = MkFoo
No internal error is caused.
If we add a pattern synonym with the name Foo, once again it errors on Bug.hs:

{-# LANGUAGE PatternSynonyms #-}
module BugBase where

data Foo = MkFoo

pattern Foo = MkFoo

Debug information

The pop-up error (slightly formatted):

Error condition, please check your setup and/or the: 
  ghcide-code-actions-imports-exports: 
    Internal Error: Exception in plugin PluginId "ghcide-code-actions-imports-exports" while processing SMethod_TextDocumentCodeAction: 
      bug in srcspan parser CallStack (from HasCallStack): 
          error, called at src/Development/IDE/Plugin/CodeAction.hs:992:22 in hls-refactor-plugin-2.4.0.0-2s97y0YK1n42ouI0BG4EZp:Development.IDE.Plugin.CodeAction
@MathiasSven MathiasSven added status: needs triage type: bug Something isn't right: doesn't work as intended, documentation is missing/outdated, etc.. labels Jan 17, 2024
@soulomoon
Copy link
Collaborator

soulomoon commented Jan 26, 2024

I am experiencing this too.

@soulomoon
Copy link
Collaborator

soulomoon commented Jan 26, 2024

It is related to ghc giving unwanted suggestions:
https://gitlab.haskell.org/ghc/ghc/-/issues/23982
and https://gitlab.haskell.org/ghc/ghc/-/issues/18740

@soulomoon
Copy link
Collaborator

soulomoon commented Jan 26, 2024

The current codeActions use regex to parse the result which is a mess.

It might be easily fixed when using GHC's structured diagnostics #2014

@jhrcek
Copy link
Collaborator

jhrcek commented Mar 1, 2024

I'm pretty this is duplicate of #4079 which I fixed in #4080

I just tested that it works in all the cases that you reported it was broken and it works fine now.
The fix is going to be available in soon-to-be-released hls 2.7.0.0

Peek 2024-03-01 16-15

@jhrcek jhrcek closed this as completed Mar 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component: imports plugin type: bug Something isn't right: doesn't work as intended, documentation is missing/outdated, etc..
Projects
None yet
Development

No branches or pull requests

3 participants