From 57811eddf22ba1fc6a0256d3181c1dc1f6984eaa Mon Sep 17 00:00:00 2001 From: flupe Date: Wed, 8 Nov 2023 15:07:16 +0100 Subject: [PATCH] [fix #219] always qualify unopened imports --- src/Agda2Hs/Compile/Name.hs | 8 ++++---- test/QualifiedImports.agda | 4 ++++ test/golden/QualifiedImports.hs | 10 ++++++---- 3 files changed, 14 insertions(+), 8 deletions(-) diff --git a/src/Agda2Hs/Compile/Name.hs b/src/Agda2Hs/Compile/Name.hs index 9323ea34..5f1467ad 100644 --- a/src/Agda2Hs/Compile/Name.hs +++ b/src/Agda2Hs/Compile/Name.hs @@ -150,10 +150,10 @@ compileQName f (C.Qual as C.QName{} : _) -> liftTCM $ do let qual = hsModuleName $ prettyShow as lookupModuleInCurrentModule as >>= \case - (x:_) | qual /= mod -> isDatatypeModule (amodName x) >>= \case - Just{} -> return $ QualifiedAs Nothing - Nothing -> return $ QualifiedAs $ Just qual - _ -> return Nothing + (x:_) | qual /= mod -> do + isDataMod <- isJust <$> isDatatypeModule (amodName x) + return $ QualifiedAs (if isDataMod then Nothing else Just qual) + _ -> return $ QualifiedAs Nothing `catchError` \_ -> return $ QualifiedAs Nothing _ -> return $ QualifiedAs Nothing diff --git a/test/QualifiedImports.agda b/test/QualifiedImports.agda index 58168d3f..4a936123 100644 --- a/test/QualifiedImports.agda +++ b/test/QualifiedImports.agda @@ -35,3 +35,7 @@ qualFooable = Qually.doTheFoo qualDefaultBar : Qually.Foo qualDefaultBar = Qually.defaultFoo {-# COMPILE AGDA2HS qualDefaultBar #-} + +Foo : Set +Foo = Importee.Foo +{-# COMPILE AGDA2HS Foo #-} diff --git a/test/golden/QualifiedImports.hs b/test/golden/QualifiedImports.hs index 4e334e1e..96c2c666 100644 --- a/test/golden/QualifiedImports.hs +++ b/test/golden/QualifiedImports.hs @@ -1,15 +1,15 @@ module QualifiedImports where -import Importee (Foo(MkFoo), foo) +import qualified Importee (Foo(MkFoo), foo) import qualified QualifiedImportee as Qually (Foo, Fooable(defaultFoo, doTheFoo), foo, (!#)) -- ** simple qualification simpqualBar :: Int -simpqualBar = foo +simpqualBar = Importee.foo -simpfoo :: Foo -simpfoo = MkFoo +simpfoo :: Importee.Foo +simpfoo = Importee.MkFoo -- ** qualified imports @@ -25,3 +25,5 @@ qualFooable = Qually.doTheFoo qualDefaultBar :: Qually.Foo qualDefaultBar = Qually.defaultFoo +type Foo = Importee.Foo +