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

Allow specifying packages for ambiguous modules #18

Merged
merged 3 commits into from
Mar 31, 2024

Conversation

tfausak
Copy link
Owner

@tfausak tfausak commented Mar 31, 2024

Fixes #9.

Still working on tidying this up. I was surprised to find that the ghc package does not have a parser for PackageNames in it. I think the best place to get that from is Cabal-syntax.

@tfausak tfausak marked this pull request as ready for review March 31, 2024 17:07
@tfausak
Copy link
Owner Author

tfausak commented Mar 31, 2024

Note that this requires the PackageImports language extension, which is a little surprising. Anyway, here's a complete example. Starting with this module:

{-# OPTIONS_GHC -fplugin=Imp #-}
main = print Data.SemVer.initial

The import is ambiguous:

Main.hs:2:14: error: [GHC-45102]
    Ambiguous module name ‘Data.SemVer’.
    it was found in multiple packages:
    semver-0.4.0.1 semver-range-0.2.8
  |
2 | main = print Data.SemVer.initial
  |              ^^^^^^^^^^^^^^^^^^^

So we can enable this new feature to disambiguate:

{-# OPTIONS_GHC -fplugin=Imp
  -fplugin-opt=Imp:--package=Data.SemVer:semver #-}
main = print Data.SemVer.initial

But that bumps into the extension being required:

Main.hs:3:14: error: [GHC-10032]
    Package-qualified imports are not enabled
    Suggested fix: Perhaps you intended to use PackageImports
  |
3 | main = print Data.SemVer.initial
  |              ^^^^^^^^^^^^^^^^^^^

So we can add the extension:

{-# LANGUAGE PackageImports #-}
{-# OPTIONS_GHC -fplugin=Imp
  -fplugin-opt=Imp:--package=Data.SemVer:semver #-}
main = print Data.SemVer.initial

And now it works:

Version {_versionMajor = 0, _versionMinor = 0, _versionPatch = 0, _versionRelease = [], _versionMeta = []}

@tfausak tfausak added the enhancement New feature or request label Mar 31, 2024
@tfausak tfausak merged commit 44b9258 into main Mar 31, 2024
11 checks passed
@tfausak tfausak deleted the gh-9-ambiguous-module-name branch March 31, 2024 17:24
@tfausak
Copy link
Owner Author

tfausak commented Apr 16, 2024

🤔 I wonder if Imp can automatically enable the PackageImports extension when required.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Allow specifying packages for ambiguous modules
1 participant