on master help sign in
Fix problem in generating pattern matching code for records
commit78c6db644ea5bc04e3dca19a7b94b22178ecbdd0 authorEvan Czaplicki <info@elm-lang.org> dateFri 2 Aug 2013, 14:49 (13 years ago) parent28d2568
2 files changed+6−7
compiler/Generate/Cases.hs+1−1 compiler/Generate/JavaScript.hs+5−6
compiler/Generate/Cases.hs+1−1
@@ -14,7 +14,7 @@ import Transform.Substitute
1414
1515caseToMatch patterns = do
1616 v <- newVar
17− match [v] (map (first (:[])) patterns) Fail
17+ (,) v `liftM` match [v] (map (first (:[])) patterns) Fail
1818
1919newVar = do n <- guid
2020 return $ "case" ++ show n
compiler/Generate/JavaScript.hs+5−6
@@ -270,14 +270,13 @@ jsLet (defs,e') = do ds <- mapM toJS defs
270270 return $ jsFunc "" (concat ds ++ ret e) ++ "()"
271271
272272caseToJS span e ps = do
273− match <- caseToMatch ps
273+ (tempVar,match) <- caseToMatch ps
274274 e' <- toJS' e
275− let (match',stmt) = case (match,e) of
276− (Match name _ _, L _ (Var x)) -> (matchSubst [(name,deprime x)] match, "")
277− (Match name _ _, _) -> (match, assign name e')
278− _ -> (match, "")
275+ let (match',stmt) = case e of
276+ L _ (Var x) -> (matchSubst [(tempVar,deprime x)] match, "")
277+ _ -> (match, assign tempVar e')
279278 matches <- matchToJS span match'
280− return $ "function(){ " ++ stmt ++ matches ++ " }()"
279+ return $ jsFunc "" (stmt ++ matches) ++ "()"
281280
282281matchToJS span match =
283282 case match of