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

Mark imports as implicit #5

Merged
merged 2 commits into from
Mar 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion source/ghc-9.4/Imp/Ghc.hs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ newImportDecl moduleName =
Hs.ImportDecl
{ Hs.ideclExt = Hs.noAnn,
Hs.ideclSourceSrc = SourceText.NoSourceText,
Hs.ideclImplicit = False,
Hs.ideclImplicit = True,
Hs.ideclName = Hs.noLocA moduleName,
Hs.ideclPkgQual = Plugin.NoRawPkgQual,
Hs.ideclSource = Plugin.NotBoot,
Expand Down
2 changes: 1 addition & 1 deletion source/ghc-9.6/Imp/Ghc.hs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ newImportDecl moduleName =
Hs.XImportDeclPass
{ Hs.ideclAnn = Hs.noAnn,
Hs.ideclSourceText = SourceText.NoSourceText,
Hs.ideclImplicit = False
Hs.ideclImplicit = True
},
Hs.ideclName = Hs.noLocA moduleName,
Hs.ideclPkgQual = Plugin.NoRawPkgQual,
Expand Down
12 changes: 6 additions & 6 deletions source/test-suite/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -32,31 +32,31 @@ main = Hspec.hspec . Hspec.parallel . Hspec.describe "Imp" $ do
expectImp
[]
"true = Data.Bool.True"
"import qualified Data.Bool\ntrue = Data.Bool.True"
"import (implicit) qualified Data.Bool\ntrue = Data.Bool.True"
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't realize that implicit imports are output differently than normal ones. It's a bit weird that they're not even valid syntax, but I suppose that makes sense because they're supposed to be implicit anyway. It also makes the tests a little nicer because I can be sure the imports were actually inserted by Imp (rather than somehow coming from the input or parser).


Hspec.it "inserts an aliased import" $ do
expectImp
["--alias=Data.Bool:Bool"]
"true = Bool.True"
"import qualified Data.Bool as Bool\ntrue = Bool.True"
"import (implicit) qualified Data.Bool as Bool\ntrue = Bool.True"

Hspec.it "prefers later aliases over earlier ones" $ do
expectImp
["--alias=Relude.Bool:Bool", "--alias=Data.Bool:Bool"]
"true = Bool.True"
"import qualified Data.Bool as Bool\ntrue = Bool.True"
"import (implicit) qualified Data.Bool as Bool\ntrue = Bool.True"

Hspec.it "inserts an import for a qualified type" $ do
expectImp
[]
"true = True :: Data.Bool.Bool"
"import qualified Data.Bool\ntrue = True :: Data.Bool.Bool"
"import (implicit) qualified Data.Bool\ntrue = True :: Data.Bool.Bool"

Hspec.it "inserts multiple imports sorted" $ do
expectImp
[]
"true :: Relude.Bool.Bool\ntrue = Data.Bool.True"
"import qualified Data.Bool\nimport qualified Relude.Bool\ntrue :: Relude.Bool.Bool\ntrue = Data.Bool.True"
"import (implicit) qualified Data.Bool\nimport (implicit) qualified Relude.Bool\ntrue :: Relude.Bool.Bool\ntrue = Data.Bool.True"

Hspec.it "does not re-import an open import" $ do
expectImp
Expand All @@ -80,7 +80,7 @@ main = Hspec.hspec . Hspec.parallel . Hspec.describe "Imp" $ do
expectImp
[]
"import qualified Relude.Bool\ntrue :: Relude.Bool.Bool\ntrue = Data.Bool.True"
"import qualified Relude.Bool\nimport qualified Data.Bool\ntrue :: Relude.Bool.Bool\ntrue = Data.Bool.True"
"import qualified Relude.Bool\nimport (implicit) qualified Data.Bool\ntrue :: Relude.Bool.Bool\ntrue = Data.Bool.True"

expectImp :: (Stack.HasCallStack) => [String] -> String -> String -> Hspec.Expectation
expectImp arguments input expected = do
Expand Down
Loading