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 aliasing current module #17

Merged
merged 8 commits into from
Mar 30, 2024
Merged

Allow aliasing current module #17

merged 8 commits into from
Mar 30, 2024

Conversation

tfausak
Copy link
Owner

@tfausak tfausak commented Mar 30, 2024

Fixes #13.

This PR introduces a special alias source named _ that can be used as a stand-in for the current module. For example, this input:

{-# OPTIONS_GHC
  -fplugin=Imp
  -fplugin-opt=Imp:--alias=_:Self #-}
module Qualified.Example where
print = putStrLn . show
defaultMain = Self.print

Will produce this output:

module Qualified.Example where
print = putStrLn . show
defaultMain = Qualified.Example.print

Note that the name _ is special, but the name Self is not. You can use whatever you want, like This or Current. You can even set up multiple aliases for the current module if you want that for some reason.


This PR also fixes a bug where imports for the current module were incorrectly being added. Previously this input:

module Example where
undefined = Example.undefined

Would produce this output:

module Example where
import qualified Example
undefined = Example.undefined

Which is always an error since a module cannot import itself. Now no import statement will be generated in this scenario.

@tfausak tfausak added bug Something isn't working enhancement New feature or request labels Mar 30, 2024
@tfausak tfausak merged commit f530e0b into main Mar 30, 2024
11 checks passed
@tfausak tfausak deleted the gh-13-current-module branch March 30, 2024 23:16
@tfausak
Copy link
Owner Author

tfausak commented Apr 1, 2024

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

Successfully merging this pull request may close these issues.

Allow special alias for current module
1 participant