git.iko.soy/rowtype-yoga/purescript-native
on golang help sign in
Allow operator aliases for imported values
6404180Gary Burgess
examples/passing/OperatorAliasElsewhere.pursnew file+14
@@ -0,0 +1,14 @@
1+module Def where
2+
3+what :: forall a b. a -> b -> a
4+what a _ = a
5+
6+module Main where
7+
8+import Prelude
9+import Def (what)
10+import Control.Monad.Eff.Console
11+
12+infixl 4 what as ?!
13+
14+main = log $ "Done" ?! true
src/Language/PureScript/AST/Declarations.hs+1−1
@@ -186,7 +186,7 @@ data Declaration
186 -- |
186 -- |
187 -- A fixity declaration (fixity data, operator name, value the operator is an alias for)
187 -- A fixity declaration (fixity data, operator name, value the operator is an alias for)
188 --
188 --
189− | FixityDeclaration Fixity String (Maybe Ident)
189+ | FixityDeclaration Fixity String (Maybe (Qualified Ident))
190 -- |
190 -- |
191 -- A module import (module name, qualified/unqualified/hiding, optional "qualified as" name)
191 -- A module import (module name, qualified/unqualified/hiding, optional "qualified as" name)
192 -- TODO: also a boolean specifying whether the old `qualified` syntax was used, so a warning can be raised in desugaring (remove for 0.9)
192 -- TODO: also a boolean specifying whether the old `qualified` syntax was used, so a warning can be raised in desugaring (remove for 0.9)
src/Language/PureScript/CoreFn/Desugar.hs+2−2
@@ -55,8 +55,7 @@ moduleToCoreFn env (A.Module _ coms mn decls (Just exps)) =
55 declToCoreFn ss com (A.ValueDeclaration name _ _ (Right e)) =
55 declToCoreFn ss com (A.ValueDeclaration name _ _ (Right e)) =
56 [NonRec name (exprToCoreFn ss com Nothing e)]
56 [NonRec name (exprToCoreFn ss com Nothing e)]
57 declToCoreFn ss com (A.FixityDeclaration _ name (Just alias)) =
57 declToCoreFn ss com (A.FixityDeclaration _ name (Just alias)) =
58− let qname = Qualified (Just mn) alias
59− in [NonRec (Op name) (Var (ss, com, Nothing, getValueMeta qname) (Qualified Nothing alias))]
58+ [NonRec (Op name) (Var (ss, com, Nothing, getValueMeta alias) alias)]
60 declToCoreFn ss _ (A.BindingGroupDeclaration ds) =
59 declToCoreFn ss _ (A.BindingGroupDeclaration ds) =
61 [Rec $ map (\(name, _, e) -> (name, exprToCoreFn ss [] Nothing e)) ds]
60 [Rec $ map (\(name, _, e) -> (name, exprToCoreFn ss [] Nothing e)) ds]
62 declToCoreFn ss com (A.TypeClassDeclaration name _ supers members) =
61 declToCoreFn ss com (A.TypeClassDeclaration name _ supers members) =
@@ -197,6 +196,7 @@ findQualModules decls =
197 where
196 where
198 fqDecls :: A.Declaration -> [ModuleName]
197 fqDecls :: A.Declaration -> [ModuleName]
199 fqDecls (A.TypeInstanceDeclaration _ _ (Qualified (Just mn) _) _ _) = [mn]
198 fqDecls (A.TypeInstanceDeclaration _ _ (Qualified (Just mn) _) _ _) = [mn]
199+ fqDecls (A.FixityDeclaration _ _ (Just (Qualified (Just mn) _))) = [mn]
200 fqDecls _ = []
200 fqDecls _ = []
201
201
202 fqValues :: A.Expr -> [ModuleName]
202 fqValues :: A.Expr -> [ModuleName]
src/Language/PureScript/Docs/AsMarkdown.hs+8−9
@@ -31,21 +31,22 @@ moduleAsMarkdown Module{..} = do
31 headerLevel 2 $ "Module " ++ modName
31 headerLevel 2 $ "Module " ++ modName
32 spacer
32 spacer
33 for_ modComments tell'
33 for_ modComments tell'
34− mapM_ declAsMarkdown modDeclarations
34+ mapM_ (declAsMarkdown modName) modDeclarations
35 spacer
35 spacer
36
36
37−declAsMarkdown :: Declaration -> Docs
37+declAsMarkdown :: String -> Declaration -> Docs
38−declAsMarkdown decl@Declaration{..} = do
38+declAsMarkdown mn decl@Declaration{..} = do
39+ let options = defaultRenderTypeOptions { currentModule = Just (P.moduleNameFromString mn) }
39 headerLevel 4 (ticks declTitle)
40 headerLevel 4 (ticks declTitle)
40 spacer
41 spacer
41
42
42 let (instances, children) = partition (isChildInstance . cdeclInfo) declChildren
43 let (instances, children) = partition (isChildInstance . cdeclInfo) declChildren
43 fencedBlock $ do
44 fencedBlock $ do
44− tell' (codeToString $ Render.renderDeclaration decl)
45+ tell' (codeToString $ Render.renderDeclarationWithOptions options decl)
45 zipWithM_ (\f c -> tell' (childToString f c)) (First : repeat NotFirst) children
46 zipWithM_ (\f c -> tell' (childToString f c)) (First : repeat NotFirst) children
46 spacer
47 spacer
47
48
48− for_ declFixity (\(fixity, alias) -> fixityAsMarkdown fixity alias >> spacer)
49+ for_ declFixity (\fixity -> fixityAsMarkdown fixity >> spacer)
49
50
50 for_ declComments tell'
51 for_ declComments tell'
51
52
@@ -68,11 +69,9 @@ codeToString = outputWith elemAsMarkdown
68 elemAsMarkdown (Keyword x) = x
69 elemAsMarkdown (Keyword x) = x
69 elemAsMarkdown Space = " "
70 elemAsMarkdown Space = " "
70
71
71−fixityAsMarkdown :: P.Fixity -> Maybe String -> Docs
72+fixityAsMarkdown :: P.Fixity -> Docs
72−fixityAsMarkdown (P.Fixity associativity precedence) alias =
73+fixityAsMarkdown (P.Fixity associativity precedence) =
73− -- TODO: link alias name to member
74 tell' $ concat [ "_"
74 tell' $ concat [ "_"
75− , maybe "" (\i -> "alias for " ++ i ++ " - ") alias
76 , associativityStr
75 , associativityStr
77 , " / precedence "
76 , " / precedence "
78 , show precedence
77 , show precedence
src/Language/PureScript/Docs/Convert.hs+8−6
@@ -71,7 +71,7 @@ type IntermediateDeclaration
71-- with their associativity and precedence.
71-- with their associativity and precedence.
72data DeclarationAugment
72data DeclarationAugment
73 = AugmentChild ChildDeclaration
73 = AugmentChild ChildDeclaration
74− | AugmentFixity P.Fixity (Maybe P.Ident)
74+ | AugmentFixity P.Fixity
75
75
76-- | Augment top-level declarations; the second pass. See the comments under
76-- | Augment top-level declarations; the second pass. See the comments under
77-- the type synonym IntermediateDeclaration for more information.
77-- the type synonym IntermediateDeclaration for more information.
@@ -89,8 +89,8 @@ augmentDeclarations (partitionEithers -> (augments, toplevels)) =
89 case a of
89 case a of
90 AugmentChild child ->
90 AugmentChild child ->
91 d { declChildren = declChildren d ++ [child] }
91 d { declChildren = declChildren d ++ [child] }
92− AugmentFixity fixity alias ->
92+ AugmentFixity fixity ->
93− d { declFixity = Just (fixity, P.runIdent <$> alias) }
93+ d { declFixity = Just fixity }
94
94
95-- | Add the default operator fixity for operators which do not have associated
95-- | Add the default operator fixity for operators which do not have associated
96-- fixity declarations.
96-- fixity declarations.
@@ -100,7 +100,7 @@ augmentDeclarations (partitionEithers -> (augments, toplevels)) =
100addDefaultFixity :: Declaration -> Declaration
100addDefaultFixity :: Declaration -> Declaration
101addDefaultFixity decl@Declaration{..}
101addDefaultFixity decl@Declaration{..}
102 | isOp declTitle && isNothing declFixity =
102 | isOp declTitle && isNothing declFixity =
103− decl { declFixity = Just (defaultFixity, Nothing) }
103+ decl { declFixity = Just defaultFixity }
104 | otherwise =
104 | otherwise =
105 decl
105 decl
106 where
106 where
@@ -173,8 +173,10 @@ convertDeclaration (P.TypeInstanceDeclaration _ constraints className tys _) tit
173
173
174 childDecl = ChildDeclaration title Nothing Nothing (ChildInstance constraints classApp)
174 childDecl = ChildDeclaration title Nothing Nothing (ChildInstance constraints classApp)
175 classApp = foldl P.TypeApp (P.TypeConstructor className) tys
175 classApp = foldl P.TypeApp (P.TypeConstructor className) tys
176−convertDeclaration (P.FixityDeclaration fixity _ alias) title =
176+convertDeclaration (P.FixityDeclaration fixity _ Nothing) title =
177− Just (Left ([title], AugmentFixity fixity alias))
177+ Just (Left ([title], AugmentFixity fixity))
178+convertDeclaration (P.FixityDeclaration fixity _ (Just alias)) title =
179+ Just $ Right $ (mkDeclaration title (AliasDeclaration alias fixity)) { declFixity = Just fixity }
178convertDeclaration (P.PositionedDeclaration srcSpan com d') title =
180convertDeclaration (P.PositionedDeclaration srcSpan com d') title =
179 fmap (addComments . addSourceSpan) (convertDeclaration d' title)
181 fmap (addComments . addSourceSpan) (convertDeclaration d' title)
180 where
182 where
src/Language/PureScript/Docs/Render.hs+11
@@ -61,8 +61,19 @@ renderDeclarationWithOptions opts Declaration{..} =
61
61
62 isTypeClassMember (ChildTypeClassMember _) = True
62 isTypeClassMember (ChildTypeClassMember _) = True
63 isTypeClassMember _ = False
63 isTypeClassMember _ = False
64+ AliasDeclaration for (P.Fixity associativity precedence) ->
65+ [ keywordFixity associativity
66+ , syntax $ show precedence
67+ , ident $ P.showQualified P.runIdent $ dequalifyCurrentModule for
68+ , keyword "as"
69+ , ident . tail . init $ declTitle
70+ ]
71+
64 where
72 where
65 renderType' = renderTypeWithOptions opts
73 renderType' = renderTypeWithOptions opts
74+ dequalifyCurrentModule (P.Qualified mn a)
75+ | mn == currentModule opts = P.Qualified Nothing a
76+ | otherwise = P.Qualified mn a
66
77
67renderChildDeclaration :: ChildDeclaration -> RenderedCode
78renderChildDeclaration :: ChildDeclaration -> RenderedCode
68renderChildDeclaration = renderChildDeclarationWithOptions defaultRenderTypeOptions
79renderChildDeclaration = renderChildDeclarationWithOptions defaultRenderTypeOptions
src/Language/PureScript/Docs/RenderedCode/Render.hs+7−2
@@ -9,7 +9,7 @@ module Language.PureScript.Docs.RenderedCode.Render (
9 defaultRenderTypeOptions,
9 defaultRenderTypeOptions,
10 renderTypeWithOptions
10 renderTypeWithOptions
11) where
11) where
12−
12+
13import Prelude ()
13import Prelude ()
14import Prelude.Compat
14import Prelude.Compat
15
15
@@ -172,10 +172,15 @@ renderType = renderTypeWithOptions defaultRenderTypeOptions
172
172
173data RenderTypeOptions = RenderTypeOptions
173data RenderTypeOptions = RenderTypeOptions
174 { prettyPrintObjects :: Bool
174 { prettyPrintObjects :: Bool
175+ , currentModule :: Maybe ModuleName
175 }
176 }
176
177
177defaultRenderTypeOptions :: RenderTypeOptions
178defaultRenderTypeOptions :: RenderTypeOptions
178−defaultRenderTypeOptions = RenderTypeOptions { prettyPrintObjects = True }
179+defaultRenderTypeOptions =
180+ RenderTypeOptions
181+ { prettyPrintObjects = True
182+ , currentModule = Nothing
183+ }
179
184
180renderTypeWithOptions :: RenderTypeOptions -> Type -> RenderedCode
185renderTypeWithOptions :: RenderTypeOptions -> Type -> RenderedCode
181renderTypeWithOptions opts =
186renderTypeWithOptions opts =
src/Language/PureScript/Docs/RenderedCode/Types.hs+6
@@ -28,6 +28,7 @@ module Language.PureScript.Docs.RenderedCode.Types
28 , keywordClass
28 , keywordClass
29 , keywordInstance
29 , keywordInstance
30 , keywordWhere
30 , keywordWhere
31+ , keywordFixity
31 ) where
32 ) where
32
33
33import Prelude ()
34import Prelude ()
@@ -189,3 +190,8 @@ keywordInstance = keyword "instance"
189
190
190keywordWhere :: RenderedCode
191keywordWhere :: RenderedCode
191keywordWhere = keyword "where"
192keywordWhere = keyword "where"
193+
194+keywordFixity :: P.Associativity -> RenderedCode
195+keywordFixity P.Infixl = keyword "infixl"
196+keywordFixity P.Infixr = keyword "infixr"
197+keywordFixity P.Infix = keyword "infix"
src/Language/PureScript/Docs/Types.hs+19−7
@@ -84,7 +84,7 @@ data Declaration = Declaration
84 , declComments :: Maybe String
84 , declComments :: Maybe String
85 , declSourceSpan :: Maybe P.SourceSpan
85 , declSourceSpan :: Maybe P.SourceSpan
86 , declChildren :: [ChildDeclaration]
86 , declChildren :: [ChildDeclaration]
87− , declFixity :: Maybe (P.Fixity, Maybe String)
87+ , declFixity :: Maybe P.Fixity -- TODO: remove in 0.9
88 , declInfo :: DeclarationInfo
88 , declInfo :: DeclarationInfo
89 }
89 }
90 deriving (Show, Eq, Ord)
90 deriving (Show, Eq, Ord)
@@ -126,6 +126,12 @@ data DeclarationInfo
126 -- members are represented as child declarations.
126 -- members are represented as child declarations.
127 --
127 --
128 | TypeClassDeclaration [(String, Maybe P.Kind)] [P.Constraint]
128 | TypeClassDeclaration [(String, Maybe P.Kind)] [P.Constraint]
129+
130+ -- |
131+ -- An operator alias declaration, with the member the alias is for and the
132+ -- operator's fixity.
133+ --
134+ | AliasDeclaration (P.Qualified P.Ident) P.Fixity
129 deriving (Show, Eq, Ord)
135 deriving (Show, Eq, Ord)
130
136
131declInfoToString :: DeclarationInfo -> String
137declInfoToString :: DeclarationInfo -> String
@@ -134,6 +140,7 @@ declInfoToString (DataDeclaration _ _) = "data"
134declInfoToString (ExternDataDeclaration _) = "externData"
140declInfoToString (ExternDataDeclaration _) = "externData"
135declInfoToString (TypeSynonymDeclaration _ _) = "typeSynonym"
141declInfoToString (TypeSynonymDeclaration _ _) = "typeSynonym"
136declInfoToString (TypeClassDeclaration _ _) = "typeClass"
142declInfoToString (TypeClassDeclaration _ _) = "typeClass"
143+declInfoToString (AliasDeclaration _ _) = "alias"
137
144
138data ChildDeclaration = ChildDeclaration
145data ChildDeclaration = ChildDeclaration
139 { cdeclTitle :: String
146 { cdeclTitle :: String
@@ -307,12 +314,10 @@ asDeclaration =
307 <*> key "fixity" (perhaps asFixity)
314 <*> key "fixity" (perhaps asFixity)
308 <*> key "info" asDeclarationInfo
315 <*> key "info" asDeclarationInfo
309
316
310−asFixity :: Parse PackageError (P.Fixity, Maybe String)
317+asFixity :: Parse PackageError P.Fixity
311−asFixity = do
318+asFixity =
312− fixity <- P.Fixity <$> key "associativity" asAssociativity
319+ P.Fixity <$> key "associativity" asAssociativity
313− <*> key "precedence" asIntegral
320+ <*> key "precedence" asIntegral
314− alias <- keyMay "alias" asString
315− return (fixity, alias)
316
321
317parseAssociativity :: String -> Maybe P.Associativity
322parseAssociativity :: String -> Maybe P.Associativity
318parseAssociativity str = case str of
323parseAssociativity str = case str of
@@ -341,6 +346,9 @@ asDeclarationInfo = do
341 "typeClass" ->
346 "typeClass" ->
342 TypeClassDeclaration <$> key "arguments" asTypeArguments
347 TypeClassDeclaration <$> key "arguments" asTypeArguments
343 <*> key "superclasses" (eachInArray asConstraint)
348 <*> key "superclasses" (eachInArray asConstraint)
349+ "alias" ->
350+ AliasDeclaration <$> key "for" asQualifiedIdent
351+ <*> key "fixity" asFixity
344 other ->
352 other ->
345 throwCustomError (InvalidDeclarationType other)
353 throwCustomError (InvalidDeclarationType other)
346
354
@@ -394,6 +402,9 @@ asConstraint = (,) <$> nth 0 asQualifiedProperName
394asQualifiedProperName :: Parse e (P.Qualified P.ProperName)
402asQualifiedProperName :: Parse e (P.Qualified P.ProperName)
395asQualifiedProperName = fromAesonParser
403asQualifiedProperName = fromAesonParser
396
404
405+asQualifiedIdent :: Parse e (P.Qualified P.Ident)
406+asQualifiedIdent = fromAesonParser
407+
397asBookmarks :: Parse BowerError [Bookmark]
408asBookmarks :: Parse BowerError [Bookmark]
398asBookmarks = eachInArray asBookmark
409asBookmarks = eachInArray asBookmark
399
410
@@ -478,6 +489,7 @@ instance A.ToJSON DeclarationInfo where
478 ExternDataDeclaration kind -> ["kind" .= kind]
489 ExternDataDeclaration kind -> ["kind" .= kind]
479 TypeSynonymDeclaration args ty -> ["arguments" .= args, "type" .= ty]
490 TypeSynonymDeclaration args ty -> ["arguments" .= args, "type" .= ty]
480 TypeClassDeclaration args super -> ["arguments" .= args, "superclasses" .= super]
491 TypeClassDeclaration args super -> ["arguments" .= args, "superclasses" .= super]
492+ AliasDeclaration for fixity -> ["for" .= for, "fixity" .= fixity]
481
493
482instance A.ToJSON ChildDeclarationInfo where
494instance A.ToJSON ChildDeclarationInfo where
483 toJSON info = A.object $ "declType" .= childDeclInfoToString info : props
495 toJSON info = A.object $ "declType" .= childDeclInfoToString info : props
src/Language/PureScript/Externs.hs+1−1
@@ -73,7 +73,7 @@ data ExternsFixity = ExternsFixity
73 -- | The operator symbol
73 -- | The operator symbol
74 , efOperator :: String
74 , efOperator :: String
75 -- | The value the operator is an alias for
75 -- | The value the operator is an alias for
76− , efAlias :: Maybe Ident
76+ , efAlias :: Maybe (Qualified Ident)
77 } deriving (Show, Read)
77 } deriving (Show, Read)
78
78
79-- | A type or value declaration appearing in an externs file
79-- | A type or value declaration appearing in an externs file
src/Language/PureScript/ModuleDependencies.hs+1
@@ -58,6 +58,7 @@ usedModules = let (f, _, _, _, _) = everythingOnValues (++) forDecls forValues (
58 where
58 where
59 forDecls :: Declaration -> [ModuleName]
59 forDecls :: Declaration -> [ModuleName]
60 forDecls (ImportDeclaration mn _ _ _) = [mn]
60 forDecls (ImportDeclaration mn _ _ _) = [mn]
61+ forDecls (FixityDeclaration _ _ (Just (Qualified (Just mn) _))) = [mn]
61 forDecls _ = []
62 forDecls _ = []
62
63
63 forValues :: Expr -> [ModuleName]
64 forValues :: Expr -> [ModuleName]
src/Language/PureScript/Names.hs+1−16
@@ -13,10 +13,7 @@ import Control.Monad.Supply.Class
13
13
14import Data.List
14import Data.List
15import Data.Data
15import Data.Data
16−import Data.List.Split (splitOn)
17import Data.Aeson.TH
16import Data.Aeson.TH
18−import qualified Data.Aeson as A
19−import qualified Data.Text as T
20
17
21-- |
18-- |
22-- Names for value identifiers
19-- Names for value identifiers
@@ -81,19 +78,6 @@ showQualified :: (a -> String) -> Qualified a -> String
81showQualified f (Qualified Nothing a) = f a
78showQualified f (Qualified Nothing a) = f a
82showQualified f (Qualified (Just name) a) = runModuleName name ++ "." ++ f a
79showQualified f (Qualified (Just name) a) = runModuleName name ++ "." ++ f a
83
80
84−instance (a ~ ProperName) => A.ToJSON (Qualified a) where
85− toJSON = A.toJSON . showQualified runProperName
86−
87−instance (a ~ ProperName) => A.FromJSON (Qualified a) where
88− parseJSON =
89− A.withText "Qualified ProperName" $ \str ->
90− return $ case reverse (splitOn "." (T.unpack str)) of
91− [name] -> Qualified Nothing (ProperName name)
92− (name:rest) -> Qualified (Just (reconstructModuleName rest)) (ProperName name)
93− _ -> Qualified Nothing (ProperName "")
94− where
95− reconstructModuleName = moduleNameFromString . intercalate "." . reverse
96−
97-- |
81-- |
98-- Provide a default module name, if a name is unqualified
82-- Provide a default module name, if a name is unqualified
99--
83--
@@ -118,6 +102,7 @@ isUnqualified :: Qualified a -> Bool
118isUnqualified (Qualified Nothing _) = True
102isUnqualified (Qualified Nothing _) = True
119isUnqualified _ = False
103isUnqualified _ = False
120
104
105+$(deriveJSON (defaultOptions { sumEncoding = ObjectWithSingleField }) ''Qualified)
121$(deriveJSON (defaultOptions { sumEncoding = ObjectWithSingleField }) ''Ident)
106$(deriveJSON (defaultOptions { sumEncoding = ObjectWithSingleField }) ''Ident)
122$(deriveJSON (defaultOptions { sumEncoding = ObjectWithSingleField }) ''ProperName)
107$(deriveJSON (defaultOptions { sumEncoding = ObjectWithSingleField }) ''ProperName)
123$(deriveJSON (defaultOptions { sumEncoding = ObjectWithSingleField }) ''ModuleName)
108$(deriveJSON (defaultOptions { sumEncoding = ObjectWithSingleField }) ''ModuleName)
src/Language/PureScript/Parser/Declarations.hs+1−1
@@ -122,7 +122,7 @@ parseFixityDeclaration :: TokenParser Declaration
122parseFixityDeclaration = do
122parseFixityDeclaration = do
123 fixity <- parseFixity
123 fixity <- parseFixity
124 indented
124 indented
125− alias <- P.optionMaybe $ (Ident <$> identifier) <* reserved "as"
125+ alias <- P.optionMaybe $ parseQualified (Ident <$> identifier) <* reserved "as"
126 name <- symbol
126 name <- symbol
127 return $ FixityDeclaration fixity name alias
127 return $ FixityDeclaration fixity name alias
128
128
src/Language/PureScript/Sugar/Names.hs+2
@@ -141,6 +141,8 @@ renameInModule env imports (Module ss coms mn decls exps) =
141 (,) (pos, bound) <$> (TypeDeclaration name <$> updateTypesEverywhere pos ty)
141 (,) (pos, bound) <$> (TypeDeclaration name <$> updateTypesEverywhere pos ty)
142 updateDecl (pos, bound) (ExternDeclaration name ty) =
142 updateDecl (pos, bound) (ExternDeclaration name ty) =
143 (,) (pos, name : bound) <$> (ExternDeclaration name <$> updateTypesEverywhere pos ty)
143 (,) (pos, name : bound) <$> (ExternDeclaration name <$> updateTypesEverywhere pos ty)
144+ updateDecl (pos, bound) (FixityDeclaration fx name alias) =
145+ (,) (pos, bound) <$> (FixityDeclaration fx name <$> traverse (`updateValueName` pos) alias)
144 updateDecl s d = return (s, d)
146 updateDecl s d = return (s, d)
145
147
146 updateValue :: (Maybe SourceSpan, [Ident]) -> Expr -> m ((Maybe SourceSpan, [Ident]), Expr)
148 updateValue :: (Maybe SourceSpan, [Ident]) -> Expr -> m ((Maybe SourceSpan, [Ident]), Expr)
src/Language/PureScript/Sugar/Operators.hs+9−9
@@ -2,6 +2,7 @@
2{-# LANGUAGE FlexibleContexts #-}
2{-# LANGUAGE FlexibleContexts #-}
3{-# LANGUAGE ScopedTypeVariables #-}
3{-# LANGUAGE ScopedTypeVariables #-}
4{-# LANGUAGE RecordWildCards #-}
4{-# LANGUAGE RecordWildCards #-}
5+{-# LANGUAGE TupleSections #-}
5
6
6-- |
7-- |
7-- This module implements the desugaring pass which reapplies binary operators based
8-- This module implements the desugaring pass which reapplies binary operators based
@@ -55,9 +56,8 @@ rebracket externs ms = do
55
56
56 where
57 where
57
58
58− makeLookupEntry :: (Qualified Ident, SourceSpan, Fixity, Maybe Ident) -> Maybe (Qualified Ident, Qualified Ident)
59+ makeLookupEntry :: (Qualified Ident, SourceSpan, Fixity, Maybe (Qualified Ident)) -> Maybe (Qualified Ident, Qualified Ident)
59− makeLookupEntry (qname@(Qualified qual _), _, _, Just alias) = Just (qname, Qualified qual alias)
60+ makeLookupEntry (qname, _, _, alias) = (qname, ) <$> alias
60− makeLookupEntry _ = Nothing
61
61
62 renameAliasedOperators :: M.Map (Qualified Ident) (Qualified Ident) -> Module -> Module
62 renameAliasedOperators :: M.Map (Qualified Ident) (Qualified Ident) -> Module -> Module
63 renameAliasedOperators aliased (Module ss coms mn ds exts) = Module ss coms mn (map f' ds) exts
63 renameAliasedOperators aliased (Module ss coms mn ds exts) = Module ss coms mn (map f' ds) exts
@@ -87,16 +87,16 @@ removeParens =
87 go (Parens val) = val
87 go (Parens val) = val
88 go val = val
88 go val = val
89
89
90−externsFixities :: ExternsFile -> [(Qualified Ident, SourceSpan, Fixity, Maybe Ident)]
90+externsFixities :: ExternsFile -> [(Qualified Ident, SourceSpan, Fixity, Maybe (Qualified Ident))]
91externsFixities ExternsFile{..} =
91externsFixities ExternsFile{..} =
92− [ (Qualified (Just efModuleName) (Op op), internalModuleSourceSpan "", Fixity assoc prec, alias)
92+ [ (Qualified (Just efModuleName) (Op op), internalModuleSourceSpan "", Fixity assoc prec, alias)
93− | ExternsFixity assoc prec op alias <- efFixities
93+ | ExternsFixity assoc prec op alias <- efFixities
94− ]
94+ ]
95
95
96−collectFixities :: Module -> [(Qualified Ident, SourceSpan, Fixity, Maybe Ident)]
96+collectFixities :: Module -> [(Qualified Ident, SourceSpan, Fixity, Maybe (Qualified Ident))]
97collectFixities (Module _ _ moduleName ds _) = concatMap collect ds
97collectFixities (Module _ _ moduleName ds _) = concatMap collect ds
98 where
98 where
99− collect :: Declaration -> [(Qualified Ident, SourceSpan, Fixity, Maybe Ident)]
99+ collect :: Declaration -> [(Qualified Ident, SourceSpan, Fixity, Maybe (Qualified Ident))]
100 collect (PositionedDeclaration pos _ (FixityDeclaration fixity name alias)) =
100 collect (PositionedDeclaration pos _ (FixityDeclaration fixity name alias)) =
101 [(Qualified (Just moduleName) (Op name), pos, fixity, alias)]
101 [(Qualified (Just moduleName) (Op name), pos, fixity, alias)]
102 collect FixityDeclaration{} = internalError "Fixity without srcpos info"
102 collect FixityDeclaration{} = internalError "Fixity without srcpos info"
src/Language/PureScript/TypeChecker.hs+3−2
@@ -281,7 +281,7 @@ typeCheckAll moduleName _ ds = traverse go ds <* traverse_ checkFixities ds
281
281
282 checkFixities :: Declaration -> m ()
282 checkFixities :: Declaration -> m ()
283 checkFixities (FixityDeclaration _ name (Just alias)) = do
283 checkFixities (FixityDeclaration _ name (Just alias)) = do
284− ty <- lookupVariable moduleName (Qualified (Just moduleName) alias)
284+ ty <- lookupVariable moduleName alias
285 addValue moduleName (Op name) ty Public
285 addValue moduleName (Op name) ty Public
286 checkFixities (FixityDeclaration _ name _) = do
286 checkFixities (FixityDeclaration _ name _) = do
287 env <- getEnv
287 env <- getEnv
@@ -433,6 +433,7 @@ typeCheckModule (Module ss coms mn decls (Just exps)) = warnAndRethrow (addHint
433 where
433 where
434 getAlias :: Declaration -> Maybe Ident
434 getAlias :: Declaration -> Maybe Ident
435 getAlias (PositionedDeclaration _ _ d) = getAlias d
435 getAlias (PositionedDeclaration _ _ d) = getAlias d
436− getAlias (FixityDeclaration _ name' alias) | name == name' = alias
436+ getAlias (FixityDeclaration _ name' (Just (Qualified (Just mn') alias)))
437+ | mn == mn' && name == name' = Just alias
437 getAlias _ = Nothing
438 getAlias _ = Nothing
438 checkNonAliasesAreExported _ = return ()
439 checkNonAliasesAreExported _ = return ()