on master help sign in
Merge branch 'dev' into deriving
commit0486c90bd3fd0616e760415619b82e9bf25879c7 authorEvan Czaplicki <info@elm-lang.org> dateMon 23 Dec 2013, 17:03 (13 years ago) parent83e8bad51ee065
3 files changed+15−9
compiler/Generate/JavaScript.hs+9−8 compiler/Parse/Expression.hs+1−1 tests/good/Otherwise.elm+5
compiler/Generate/JavaScript.hs+9−8
@@ -154,14 +154,15 @@ expression (L span expr) =
154154 return $ function [] (stmts ++ [ ReturnStmt () (Just exp) ]) `call` []
155155
156156 MultiIf branches ->
157− do branches' <- forM branches $ \(b,e) -> (,) <$> expression b <*> expression e
158− return $ case last branches of
159− (L _ (Var "Basics.otherwise"), e) -> ifs (init branches') (snd (last branches'))
160− _ -> ifs branches'
161− (obj "_E.If" `call` [ ref "$moduleName", string (show span) ])
162− where
163− ifs branches finally = foldr iff finally branches
164− iff (if', then') else' = CondExpr () if' then' else'
157+ do branches' <- forM branches $ \(b,e) -> (,) <$> expression b <*> expression e
158+ return $ case last branches of
159+ (L _ (Var "Basics.otherwise"), _) -> safeIfs branches'
160+ (L _ (Literal (Boolean True)), _) -> safeIfs branches'
161+ _ -> ifs branches' (obj "_E.If" `call` [ ref "$moduleName", string (show span) ])
162+ where
163+ safeIfs branches = ifs (init branches) (snd (last branches))
164+ ifs branches finally = foldr iff finally branches
165+ iff (if', then') else' = CondExpr () if' then' else'
165166
166167 Case e cases ->
167168 do (tempVar,initialMatch) <- Case.toMatch cases
compiler/Parse/Expression.hs+1−1
@@ -157,7 +157,7 @@ ifExpr = reserved "if" >> whitespace >> (normal <|> multiIf)
157157 whitespace <?> "an 'else' branch" ; reserved "else" <?> "an 'else' branch" ; whitespace
158158 elseBranch <- expr
159159 return $ MultiIf [(bool, thenBranch),
160− (Location.sameAs elseBranch (Var "otherwise"), elseBranch)]
160+ (Location.sameAs elseBranch (Literal . Literal.Boolean $ True), elseBranch)]
161161 multiIf = MultiIf <$> spaceSep1 iff
162162 where iff = do string "|" ; whitespace
163163 b <- expr ; padded arrow
tests/good/Otherwise.elmnew file+5
@@ -0,0 +1,5 @@
1+module Otherwise where
2+
3+otherwise = 3
4+
5+main = asText <| if False then "Yay" else "Boo"