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

Bogus "Duplicate instance declarations:" error #3237

Closed
mouse07410 opened this issue Sep 30, 2022 · 15 comments
Closed

Bogus "Duplicate instance declarations:" error #3237

mouse07410 opened this issue Sep 30, 2022 · 15 comments
Labels
multi-component Issues relating to multi-component support status: blocked Not actionable, because blocked by upstream/GHC etc. type: bug Something isn't right: doesn't work as intended, documentation is missing/outdated, etc..

Comments

@mouse07410
Copy link

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 mouse07410 added status: needs triage type: bug Something isn't right: doesn't work as intended, documentation is missing/outdated, etc.. labels Sep 30, 2022
@lf-
Copy link
Contributor

lf- commented Oct 3, 2022

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

@mouse07410
Copy link
Author

. . . 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.

@michaelpj
Copy link
Collaborator

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 michaelpj added status: blocked Not actionable, because blocked by upstream/GHC etc. and removed status: needs triage labels Oct 5, 2022
@mouse07410
Copy link
Author

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?

@lf-
Copy link
Contributor

lf- commented Oct 6, 2022

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.

@michaelpj
Copy link
Collaborator

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.

@mouse07410
Copy link
Author

@michaelpj thank you, now I understand.

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

@michaelpj
Copy link
Collaborator

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

@fendor
Copy link
Collaborator

fendor commented Oct 6, 2022

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

@soulomoon
Copy link
Collaborator

soulomoon commented Dec 25, 2023

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
Copy link
Collaborator

soulomoon commented Dec 26, 2023

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

@michaelpj michaelpj added the multi-component Issues relating to multi-component support label Jan 16, 2024
@PaulJohnson
Copy link

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.

@soulomoon
Copy link
Collaborator

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

@fendor
Copy link
Collaborator

fendor commented Jan 23, 2024

It did in my tests

@michaelpj
Copy link
Collaborator

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
multi-component Issues relating to multi-component support status: blocked Not actionable, because blocked by upstream/GHC etc. 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

6 participants