@@ -27,7 +27,6 @@ import Language.PureScript.TypeChecker.Synonyms as T
28import Data.Maybe
28import Data.Maybe
29import Data.List (nub, (\\), find, intercalate)
29import Data.List (nub, (\\), find, intercalate)
30−import Data.Monoid ((<>))
31import Data.Foldable (for_)
30import Data.Foldable (for_)
32import qualified Data.Map as M
31import qualified Data.Map as M
@@ -47,7 +46,7 @@ addDataType moduleName dtype name args dctors ctorKind = do
47 env <- getEnv
46 env <- getEnv
48 putEnv $ env { types = M.insert (Qualified (Just moduleName) name) (ctorKind, DataType args dctors) (types env) }
47 putEnv $ env { types = M.insert (Qualified (Just moduleName) name) (ctorKind, DataType args dctors) (types env) }
49 forM_ dctors $ \(dctor, tys) ->
48 forM_ dctors $ \(dctor, tys) ->
50− rethrow (strMsg ("Error in data constructor " ++ show dctor) <>) $
49+ rethrow (mkCompileError ("Error in data constructor " ++ show dctor) Nothing `combineErrors`) $
51 addDataConstructor moduleName dtype name (map fst args) dctor tys
50 addDataConstructor moduleName dtype name (map fst args) dctor tys
53addDataConstructor :: ModuleName -> DataDeclType -> ProperName -> [String] -> ProperName -> [Type] -> Check ()
52addDataConstructor :: ModuleName -> DataDeclType -> ProperName -> [String] -> ProperName -> [Type] -> Check ()
@@ -134,7 +133,7 @@ typeCheckAll mainModuleName moduleName exps = go
134 go :: [Declaration] -> Check [Declaration]
133 go :: [Declaration] -> Check [Declaration]
135 go [] = return []
134 go [] = return []
136 go (DataDeclaration dtype name args dctors : rest) = do
135 go (DataDeclaration dtype name args dctors : rest) = do
137− rethrow (strMsg ("Error in type constructor " ++ show name) <>) $ do
136+ rethrow (mkCompileError ("Error in type constructor " ++ show name) Nothing `combineErrors`) $ do
138 when (dtype == Newtype) $ checkNewtype dctors
137 when (dtype == Newtype) $ checkNewtype dctors
139 checkDuplicateTypeArguments $ map fst args
138 checkDuplicateTypeArguments $ map fst args
140 ctorKind <- kindsOf True moduleName name args (concatMap snd dctors)
139 ctorKind <- kindsOf True moduleName name args (concatMap snd dctors)
@@ -148,7 +147,7 @@ typeCheckAll mainModuleName moduleName exps = go
148 checkNewtype [(_, _)] = throwError . strMsg $ "newtypes constructors must have a single argument"
147 checkNewtype [(_, _)] = throwError . strMsg $ "newtypes constructors must have a single argument"
149 checkNewtype _ = throwError . strMsg $ "newtypes must have a single constructor"
148 checkNewtype _ = throwError . strMsg $ "newtypes must have a single constructor"
150 go (d@(DataBindingGroupDeclaration tys) : rest) = do
149 go (d@(DataBindingGroupDeclaration tys) : rest) = do
151− rethrow (strMsg "Error in data binding group" <>) $ do
150+ rethrow (mkCompileError "Error in data binding group" Nothing `combineErrors`) $ do
152 let syns = mapMaybe toTypeSynonym tys
151 let syns = mapMaybe toTypeSynonym tys
153 let dataDecls = mapMaybe toDataDecl tys
152 let dataDecls = mapMaybe toDataDecl tys
154 (syn_ks, data_ks) <- kindsOfAll moduleName syns (map (\(_, name, args, dctors) -> (name, args, concatMap snd dctors)) dataDecls)
153 (syn_ks, data_ks) <- kindsOfAll moduleName syns (map (\(_, name, args, dctors) -> (name, args, concatMap snd dctors)) dataDecls)
@@ -170,7 +169,7 @@ typeCheckAll mainModuleName moduleName exps = go
170 toDataDecl (PositionedDeclaration _ _ d') = toDataDecl d'
169 toDataDecl (PositionedDeclaration _ _ d') = toDataDecl d'
171 toDataDecl _ = Nothing
170 toDataDecl _ = Nothing
172 go (TypeSynonymDeclaration name args ty : rest) = do
171 go (TypeSynonymDeclaration name args ty : rest) = do
173− rethrow (strMsg ("Error in type synonym " ++ show name) <>) $ do
172+ rethrow (mkCompileError ("Error in type synonym " ++ show name) Nothing `combineErrors`) $ do
174 checkDuplicateTypeArguments $ map fst args
173 checkDuplicateTypeArguments $ map fst args
175 kind <- kindsOf False moduleName name args [ty]
174 kind <- kindsOf False moduleName name args [ty]
176 let args' = args `withKinds` kind
175 let args' = args `withKinds` kind
@@ -179,7 +178,7 @@ typeCheckAll mainModuleName moduleName exps = go
179 return $ TypeSynonymDeclaration name args ty : ds
178 return $ TypeSynonymDeclaration name args ty : ds
180 go (TypeDeclaration _ _ : _) = error "Type declarations should have been removed"
179 go (TypeDeclaration _ _ : _) = error "Type declarations should have been removed"
181 go (ValueDeclaration name nameKind [] (Right val) : rest) = do
180 go (ValueDeclaration name nameKind [] (Right val) : rest) = do
182− d <- rethrow (strMsg ("Error in declaration " ++ show name) <>) $ do
181+ d <- rethrow (mkCompileError ("Error in declaration " ++ show name) Nothing `combineErrors`) $ do
183 valueIsNotDefined moduleName name
182 valueIsNotDefined moduleName name
184 [(_, (val', ty))] <- typesOf mainModuleName moduleName [(name, val)]
183 [(_, (val', ty))] <- typesOf mainModuleName moduleName [(name, val)]
185 addValue moduleName name ty nameKind
184 addValue moduleName name ty nameKind
@@ -188,7 +187,7 @@ typeCheckAll mainModuleName moduleName exps = go
188 return $ d : ds
187 return $ d : ds
189 go (ValueDeclaration{} : _) = error "Binders were not desugared"
188 go (ValueDeclaration{} : _) = error "Binders were not desugared"
190 go (BindingGroupDeclaration vals : rest) = do
189 go (BindingGroupDeclaration vals : rest) = do
191− d <- rethrow (strMsg ("Error in binding group " ++ show (map (\(ident, _, _) -> ident) vals)) <>) $ do
190+ d <- rethrow (mkCompileError ("Error in binding group " ++ show (map (\(ident, _, _) -> ident) vals)) Nothing `combineErrors`) $ do
192 forM_ (map (\(ident, _, _) -> ident) vals) $ \name ->
191 forM_ (map (\(ident, _, _) -> ident) vals) $ \name ->
193 valueIsNotDefined moduleName name
192 valueIsNotDefined moduleName name
194 tys <- typesOf mainModuleName moduleName $ map (\(ident, _, ty) -> (ident, ty)) vals
193 tys <- typesOf mainModuleName moduleName $ map (\(ident, _, ty) -> (ident, ty)) vals
@@ -208,7 +207,7 @@ typeCheckAll mainModuleName moduleName exps = go
208 ds <- go rest
207 ds <- go rest
209 return $ d : ds
208 return $ d : ds
210 go (d@(ExternDeclaration importTy name _ ty) : rest) = do
209 go (d@(ExternDeclaration importTy name _ ty) : rest) = do
211− rethrow (strMsg ("Error in foreign import declaration " ++ show name) <>) $ do
210+ rethrow (mkCompileError ("Error in foreign import declaration " ++ show name) Nothing `combineErrors`) $ do
212 env <- getEnv
211 env <- getEnv
213 kind <- kindOf moduleName ty
212 kind <- kindOf moduleName ty
214 guardWith (strMsg "Expected kind *") $ kind == Star
213 guardWith (strMsg "Expected kind *") $ kind == Star