diff --git a/examples/failing/2197-shouldFail.purs b/examples/failing/2197-shouldFail.purs new file mode 100644 index 0000000000..a211f195d0 --- /dev/null +++ b/examples/failing/2197-shouldFail.purs @@ -0,0 +1,10 @@ +-- @shouldFailWith ScopeConflict +module Main where + +import Prim as P +import Prim (Number) + +type Number = P.Number + +z :: Number +z = 0.0 diff --git a/examples/failing/2197-shouldFail2.purs b/examples/failing/2197-shouldFail2.purs new file mode 100644 index 0000000000..fb1b11b5d7 --- /dev/null +++ b/examples/failing/2197-shouldFail2.purs @@ -0,0 +1,7 @@ +-- @shouldFailWith UnknownName +module Main where + +import Prim (Boolean) + +z :: Number +z = 0.0 diff --git a/examples/passing/2197-1.purs b/examples/passing/2197-1.purs new file mode 100644 index 0000000000..a0c808f350 --- /dev/null +++ b/examples/passing/2197-1.purs @@ -0,0 +1,12 @@ +module Main where + +import Control.Monad.Eff.Console +import Prim as P + +type Number = P.Number +type Test = {} + +z :: Number +z = 0.0 + +main = log "Done" diff --git a/examples/passing/2197-2.purs b/examples/passing/2197-2.purs new file mode 100644 index 0000000000..94354e94cd --- /dev/null +++ b/examples/passing/2197-2.purs @@ -0,0 +1,11 @@ +module Main where + +import Control.Monad.Eff.Console +import Prim (Int) + +type Number = Int + +z :: Number +z = 0 + +main = log "Done" diff --git a/src/Language/PureScript/AST/Declarations.hs b/src/Language/PureScript/AST/Declarations.hs index d897ee0a7c..a4ea2fdd78 100644 --- a/src/Language/PureScript/AST/Declarations.hs +++ b/src/Language/PureScript/AST/Declarations.hs @@ -229,12 +229,19 @@ getModuleSourceSpan (Module ss _ _ _ _) = ss -- | -- Add an import declaration for a module if it does not already explicitly import it. -- +-- Will not import an unqualified module if that module has already been imported qualified. +-- (See #2197) +-- addDefaultImport :: Qualified ModuleName -> Module -> Module addDefaultImport (Qualified toImportAs toImport) m@(Module ss coms mn decls exps) = if isExistingImport `any` decls || mn == toImport then m else Module ss coms mn (ImportDeclaration (ss, []) toImport Implicit toImportAs : decls) exps where - isExistingImport (ImportDeclaration _ mn' _ as') | mn' == toImport && as' == toImportAs = True + isExistingImport (ImportDeclaration _ mn' _ as') + | mn' == toImport = + case toImportAs of + Nothing -> True + _ -> as' == toImportAs isExistingImport _ = False -- | Adds import declarations to a module for an implicit Prim import and Prim @@ -244,8 +251,8 @@ importPrim = let primModName = ModuleName [ProperName C.prim] in - addDefaultImport (Qualified Nothing primModName) - . addDefaultImport (Qualified (Just primModName) primModName) + addDefaultImport (Qualified (Just primModName) primModName) + . addDefaultImport (Qualified Nothing primModName) -- | -- An item in a list of explicit imports or exports diff --git a/src/Language/PureScript/Docs/Prim.hs b/src/Language/PureScript/Docs/Prim.hs index 2a5e62c641..aa8b68c3e4 100644 --- a/src/Language/PureScript/Docs/Prim.hs +++ b/src/Language/PureScript/Docs/Prim.hs @@ -12,7 +12,7 @@ import qualified Language.PureScript as P primDocsModule :: Module primDocsModule = Module { modName = P.moduleNameFromString "Prim" - , modComments = Just "The Prim module is embedded in the PureScript compiler in order to provide compiler support for certain types — for example, value literals, or syntax sugar." + , modComments = Just "The Prim module is embedded in the PureScript compiler in order to provide compiler support for certain types — for example, value literals, or syntax sugar. It is implicitly imported unqualified in every module except those that list it as a qualified import." , modDeclarations = [ function , array