haskell-language-server icon indicating copy to clipboard operation
haskell-language-server copied to clipboard

Bogus "Duplicate instance declarations:" error

Open mouse07410 opened this issue 3 years ago • 14 comments

Your environment

  • MacOS Monterey 12.6 with Xcode-14
  • GHC-9.4.2
  • Cabal-3.8.1.0
  • HLS 1.8.0.0 installed via ghcup
  • hlint v3.4.1
  • VS Code 1.71.2 with vscode-haskell (Haskell for VIsual Studio Code) v2.2.1

Steps to reproduce and Actual behavior

At some point in time, HLS complains about "Duplicate instance declarations" which don't make sense because both refer to the same definition - same file and line number (aka, the same place).

Here's an example:

Duplicate instance declarations:
  instance Functor Point3D
     -- Defined at /Users/ur20980/src/stepic-tests/src/Lib.hs:523:10
  instance Functor Point3D
     -- Defined at /Users/ur20980/src/stepic-tests/src/Lib.hs:523:10  typecheck

Expected behaviour

Understand that one entry in one file is not a duplicate of itself?

Debug information

This is an intermittent problem. Usually it clears up when I restart HLS within VS Code (don't even need to restart VS Code itself).

mouse07410 avatar Sep 30 '22 16:09 mouse07410

I've also hit this recently on ghc-9.4.2. My wild speculation is that it might be something like is described in this section, related to mishandling of multiple home units: https://well-typed.com/blog/2022/01/multiple-home-units/#closure-property-for-home-units

lf- avatar Oct 03 '22 00:10 lf-

. . . mishandling of multiple home units . . .

I don't know - but I doubt that "multiple home units" is the cause, because in my case there are no such dependencies.

mouse07410 avatar Oct 03 '22 01:10 mouse07410

It sounds an issue with our hacked up support for multiple home units indeed, we should revisit this after the proper support is merged.

michaelpj avatar Oct 05 '22 11:10 michaelpj

It sounds an issue with our hacked up support for multiple home units indeed

But I do not have multiple homes...? Or are you saying that "multiple home units" mistakenly triggers here?

mouse07410 avatar Oct 06 '22 02:10 mouse07410

likewise; in my project i hit this in, there's no home unit depending on non home unit depending on home unit problem. A and B are both home units.

dependency graph looks like A -> B, and the alleged duplicate instance was in B, from recollection.

lf- avatar Oct 06 '22 02:10 lf-

There is an ambiguity. We currently have some hacks to load multiple components together "as if" they were multiple home units. This is not 100% reliable and can result in this kind of issue. You typically see it when working on a test or exe component as that's a point where we need to load multiple components.

"True" support for multiple home units is indeed not implemented yet.

michaelpj avatar Oct 06 '22 08:10 michaelpj

@michaelpj thank you, now I understand.

In your opinion, how near are we to having this solved?

mouse07410 avatar Oct 06 '22 09:10 mouse07410

I'm not actually sure where we are with that, @fendor do we have a tracking issue?

michaelpj avatar Oct 06 '22 12:10 michaelpj

Depends. Fully correctly? Still pretty far. Best effort, sort-of-kind-of correct? Actually very close, maybe by the end of the year?

fendor avatar Oct 06 '22 12:10 fendor

I have another one which is off by a line?

  instance Hashable KeyValue
    -- Defined at /Users/ares/src/haskell-language-server/hls-graph/src/Development/IDE/Graph/Internal/Types.hs:145:10
  instance Hashable KeyValue
    -- Defined at /Users/ares/src/haskell-language-server/hls-graph/src/Development/IDE/Graph/Internal/Types.hs:146:10typecheck

also related to #3738?

soulomoon avatar Dec 25 '23 04:12 soulomoon

The problem does goes away, swtiching to cabal head, with cabal's multiple home unites feature enabled

soulomoon avatar Dec 26 '23 07:12 soulomoon

Just getting rid of most of these would be a benefit. Depending on which files I'm editing I can get hundreds of them, and real error messages are just buried.

PaulJohnson avatar Jan 19 '24 13:01 PaulJohnson

Just getting rid of most of these would be a benefit. Depending on which files I'm editing I can get hundreds of them, and real error messages are just buried.

Is switching to cabal head help in your case? @PaulJohnson

soulomoon avatar Jan 23 '24 03:01 soulomoon

It did in my tests

fendor avatar Jan 23 '24 09:01 fendor

This should be fixed with the new multi-component support.

michaelpj avatar May 15 '24 13:05 michaelpj