Skip to content

DeriveAnyClass causes "Internal Error: initTcWithGbl failed" #3942

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

Closed
MathiasSven opened this issue Jan 12, 2024 · 3 comments · Fixed by #4020
Closed

DeriveAnyClass causes "Internal Error: initTcWithGbl failed" #3942

MathiasSven opened this issue Jan 12, 2024 · 3 comments · Fixed by #4020
Labels
component: hls-class-plugin type: bug Something isn't right: doesn't work as intended, documentation is missing/outdated, etc..

Comments

@MathiasSven
Copy link

When DeriveAnyClass is enabled, attempting to "hover" (inspect) a deriving A where A is a class with at least one method will cause HLS to have an internal error.

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

{-# LANGUAGE Haskell98 #-}
{-# LANGUAGE DeriveAnyClass #-}

module Main where

class C a where
  foo :: a -> Int

newtype Foo = MkFoo Int
  deriving Num

newtype Bar a = MkBar a
  deriving C

main :: IO ()
main = return ()

Expected behaviour

The code above should only result in a missing-methods warning on deriving Num and deriving C

Actual behaviour

Hovering over Num gives you the issue

• No explicit implementation for
    ‘+’, ‘*’, ‘abs’, ‘signum’, ‘fromInteger’, and (either ‘negate’

And over C

• No explicit implementation for
    ‘foo’

This is expected, however, when hovering over either HLS also gives an error condition pop-up every time they are hovered:

Error condition, please check your setup and/or the 
issue tracker: class: Internal Error: initTcWithGbl failed
@MathiasSven MathiasSven added status: needs triage type: bug Something isn't right: doesn't work as intended, documentation is missing/outdated, etc.. labels Jan 12, 2024
@soulomoon

This comment has been minimized.

@soulomoon
Copy link
Collaborator

soulomoon commented Jan 27, 2024

I found something really weired in hls-class-plugin. Fixing it should fix the this error

isClassNodeIdentifier :: IdentifierDetails a -> Bool
isClassNodeIdentifier ident = (isNothing . identType) ident && Use `Set.member` identInfo ident

@soulomoon
Copy link
Collaborator

soulomoon commented Jan 27, 2024

There are many holes in hls-class-plugin.

  1. bug in isClassNodeIdentifier that do not classify idenfitifer correctly. Could be solved by fix isClassNodeIdentifier in hls-class-plugin #4020 . It would stop the Internal Error: initTcWithGbl failed
  2. also there is another bug, we should not invoke such code action in deriving expression, which require us to back trace to its parents to see if it is derving expression. not fixed yet

soulomoon added a commit that referenced this issue Feb 7, 2024
Partially fix #3942, by handling isClassNodeIdentifier correctly.

---------

Co-authored-by: Michael Peyton Jones <me@michaelpj.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component: hls-class-plugin 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