Skip to content

Ambiguity problem with re-exports and multiple packages #734

@mrBliss

Description

@mrBliss

To reproduce the problem:

  • Clone https://github.com/mrBliss/ghcide-bug.
    This repo consists of three packages: a, b, and c.

    b depends on a, and c depends on both a and b.

    Each package contains a single module: A.hs, B.hs, and C.hs respectively.

    • A.hs defines and exports data Foo = Foo
    • B.hs re-exports A
    • C.hs imports both A and B and defines a value foo :: Foo. Important: both A and B export this same Foo type.

    This repo has a multi-component hie.yaml that uses cabal for building.

  • Open C.hs and start ghcide for the entire ghcide-bug project (not just the c cabal package).

  • Now open A.hs while C.hs is still open in your editor (and thus ghcide session).

  • Now go back to C.hs, suddenly you get an error:

    typecheck: Ambiguous occurrence ‘Foo’
    It could refer to either ‘Foo’,
                             imported from ‘A’ at C.hs:3:1-8
                             (and originally defined
                                at A.hs:3:1-14)
                          or ‘Foo’,
                             imported from ‘B’ at C.hs:4:1-8
                             (and originally defined in ‘A’)
    

    It seems that by opening A.hs, Foo appears to get reloaded in the ghcide session. However, the b package is somehow not properly reloaded, so that it still exports the old version of Foo. Now two versions of Foo are in scope in C.hs.

This makes it impossible for me to use ghcide in a downstream package while at the same time opening a module from an upstream package.

My setup:

Metadata

Metadata

Assignees

No one assigned

    Labels

    component: ghcidemulti-componentIssues relating to multi-component supportstatus: needs infoNot actionable, because there's missing informationtype: bugSomething isn't right: doesn't work as intended, documentation is missing/outdated, etc..

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions