Skip to content

Commit

Permalink
[fix #219] always qualify unopened imports
Browse files Browse the repository at this point in the history
  • Loading branch information
flupe committed Nov 10, 2023
1 parent 15314cd commit 57811ed
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 8 deletions.
8 changes: 4 additions & 4 deletions src/Agda2Hs/Compile/Name.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 4 additions & 0 deletions test/QualifiedImports.agda
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,7 @@ qualFooable = Qually.doTheFoo
qualDefaultBar : Qually.Foo
qualDefaultBar = Qually.defaultFoo
{-# COMPILE AGDA2HS qualDefaultBar #-}

Foo : Set
Foo = Importee.Foo
{-# COMPILE AGDA2HS Foo #-}
10 changes: 6 additions & 4 deletions test/golden/QualifiedImports.hs
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -25,3 +25,5 @@ qualFooable = Qually.doTheFoo
qualDefaultBar :: Qually.Foo
qualDefaultBar = Qually.defaultFoo

type Foo = Importee.Foo

0 comments on commit 57811ed

Please sign in to comment.