git.iko.soy/rowtype-yoga/purescript-native
on golang help sign in
Improve declaration cycle error
commit98edefb084317ec587ce352ed6b25c0c8bf3b9a2 authorDylan Simon <dylan@dylex.net> dateSun 26 Oct 2014, 20:51 (12 years ago) parentc9ca53b
1 file changed+10−1
src/Language/PureScript/Sugar/BindingGroups.hs+10−1
src/Language/PureScript/Sugar/BindingGroups.hs+10−1
@@ -24,6 +24,7 @@ module Language.PureScript.Sugar.BindingGroups (
2424import Data.Graph
2525import Data.List (nub, intersect)
2626import Data.Maybe (isJust, mapMaybe)
27+import Data.Monoid ((<>))
2728import Control.Applicative ((<$>), (<*>), pure)
2829
2930import qualified Data.Set as S
@@ -171,7 +172,15 @@ toBindingGroup moduleName (CyclicSCC ds') =
171172
172173 toBinding :: SCC Declaration -> Either ErrorStack (Ident, NameKind, Expr)
173174 toBinding (AcyclicSCC d) = return $ fromValueDecl d
174− toBinding (CyclicSCC ds) = Left $ mkErrorStack ("Cycle in value declarations " ++ unwords (map (show . getIdent) ds)) Nothing
175+ toBinding (CyclicSCC ~(d:ds)) = cycleError d ds
176+
177+ cycleError :: Declaration -> [Declaration] -> Either ErrorStack a
178+ cycleError (PositionedDeclaration p d) ds = rethrowWithPosition p $ cycleError d ds
179+ cycleError (ValueDeclaration n _ _ _ e) [] = Left $
180+ mkErrorStack ("Cycle in definition of " ++ show n) (Just (ExprError e))
181+ cycleError d ds@(_:_) = rethrow (<> mkErrorStack ("The following are not yet defined here: " ++ unwords (map (show . getIdent) ds)) Nothing) $ cycleError d []
182+ cycleError _ _ = error "Expected ValueDeclaration"
183+
175184
176185toDataBindingGroup :: SCC Declaration -> Either ErrorStack Declaration
177186toDataBindingGroup (AcyclicSCC d) = return d