Skip to content
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
10 changes: 10 additions & 0 deletions examples/failing/2197-shouldFail.purs
Original file line number Diff line number Diff line change
@@ -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
7 changes: 7 additions & 0 deletions examples/failing/2197-shouldFail2.purs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
-- @shouldFailWith UnknownName
module Main where

import Prim (Boolean)

z :: Number
z = 0.0
12 changes: 12 additions & 0 deletions examples/passing/2197-1.purs
Original file line number Diff line number Diff line change
@@ -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"
11 changes: 11 additions & 0 deletions examples/passing/2197-2.purs
Original file line number Diff line number Diff line change
@@ -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"
13 changes: 10 additions & 3 deletions src/Language/PureScript/AST/Declarations.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/Language/PureScript/Docs/Prim.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down