Skip to content

Combine type operator hint with a suggestion to enable ExplicitNamespaces if appropriate

Jade requested to merge Jade/ghc:wip/combine-type-operator-suggestions into master

As suggested in #20007 (closed) and implemented in !8895 (closed), trying to import type operators will suggest a fix to use the type keyword, without considering whether ExplicitNamespaces is enabled. This can be seen here:

 ghci> import GHC.TypeLits ((+))

<interactive>:1:22: error: [GHC-56449]
    In the import of ‘GHC.TypeLits’:
      an item called ‘(+)’ is exported, but it is a type.
    Suggested fix:
      Add the ‘type’ keyword to the import statement:
        import GHC.TypeLits ( type (+) )
ghci> import GHC.TypeLits (type (+))

<interactive>:2:27: error: [GHC-47007]
    Illegal keyword 'type'
    Suggested fix: Perhaps you intended to use ExplicitNamespaces

This patch will query whether ExplicitNamespaces is enabled and change the fix to Enable ExplicitNamespaces and add the ‘type’ keyword to the import statement: if appropriate. A test case has been added in the modules/ directory.

The new behavior looks like this

ghci> import GHC.TypeLits ((+))

<interactive>:6:22: error: [GHC-56449]
    In the import of ‘GHC.TypeLits’:
      an item called ‘(+)’ is exported, but it is a type.
    Suggested fix:
      Enable ExplicitNamespaces and add the ‘type’ keyword to the import statement:
        import GHC.TypeLits ( type (+) )

In case ExplicitNamespaces is enabled it will behave as before

ghci> import GHC.TypeLits ((+))

<interactive>:9:22: error: [GHC-56449]
    In the import of ‘GHC.TypeLits’:
      an item called ‘(+)’ is exported, but it is a type.
    Suggested fix:
      Add the ‘type’ keyword to the import statement:
        import GHC.TypeLits ( type (+) )

Merge request reports