git.iko.soy/rowtype-yoga/purescript-native
on golang help sign in
Add source position info to match errors
commit1321dab6ff80640e6386311865a55ab1224b1a56 authorBrian McKenna <brian@brianmckenna.org> dateThu 23 Apr 2015, 10:51 (12 years ago) parent0c81186
1 file changed+9−5
src/Language/PureScript/CodeGen/JS.hs+9−5
src/Language/PureScript/CodeGen/JS.hs+9−5
@@ -34,6 +34,7 @@ import Control.Monad (foldM, replicateM, forM)
3434import Control.Monad.Reader (MonadReader, asks)
3535import Control.Monad.Supply.Class
3636
37+import Language.PureScript.AST.SourcePos
3738import Language.PureScript.CodeGen.JS.AST as AST
3839import Language.PureScript.CodeGen.JS.Common as Common
3940import Language.PureScript.CoreFn
@@ -172,9 +173,9 @@ moduleToJs (Module coms mn imps exps foreigns decls) = do
172173 unApp other args = (other, args)
173174 valueToJs (Var _ ident) =
174175 return $ varToJs ident
175− valueToJs (Case _ values binders) = do
176+ valueToJs (Case (maybeSpan, _, _, _) values binders) = do
176177 vals <- mapM valueToJs values
177− bindersToJs binders vals
178+ bindersToJs maybeSpan binders vals
178179 valueToJs (Let _ ds val) = do
179180 ds' <- concat <$> mapM bindToJs ds
180181 ret <- valueToJs val
@@ -249,8 +250,8 @@ moduleToJs (Module coms mn imps exps foreigns decls) = do
249250 -- Generate code in the simplified Javascript intermediate representation for pattern match binders
250251 -- and guards.
251252 --
252− bindersToJs :: [CaseAlternative Ann] -> [JS] -> m JS
253− bindersToJs binders vals = do
253+ bindersToJs :: Maybe SourceSpan -> [CaseAlternative Ann] -> [JS] -> m JS
254+ bindersToJs maybeSpan binders vals = do
254255 valNames <- replicateM (length vals) freshName
255256 let assignments = zipWith JSVariableIntroduction valNames (map Just vals)
256257 jss <- forM binders $ \(CaseAlternative bs result) -> do
@@ -267,7 +268,10 @@ moduleToJs (Module coms mn imps exps foreigns decls) = do
267268 go _ _ _ = error "Invalid arguments to bindersToJs"
268269
269270 failedPatternError :: [String] -> JS
270− failedPatternError names = JSUnary JSNew $ JSApp (JSVar "Error") [JSBinary Add (JSStringLiteral "Failed pattern match: ") (JSArrayLiteral $ zipWith valueError names vals)]
271+ failedPatternError names = JSUnary JSNew $ JSApp (JSVar "Error") [JSBinary Add (JSStringLiteral errorMessage) (JSArrayLiteral $ zipWith valueError names vals)]
272+
273+ errorMessage :: String
274+ errorMessage = "Failed pattern match" ++ maybe "" ((" at " ++) . displaySourceSpan) maybeSpan ++ ": "
271275
272276 valueError :: String -> JS -> JS
273277 valueError _ l@(JSNumericLiteral _) = l