on master help sign in
Merge branch 'dev' into deriving
0486c90Evan Czaplicki
compiler/Generate/JavaScript.hs+9−8
@@ -154,14 +154,15 @@ expression (L span expr) =
154 return $ function [] (stmts ++ [ ReturnStmt () (Just exp) ]) `call` []
154 return $ function [] (stmts ++ [ ReturnStmt () (Just exp) ]) `call` []
155
155
156 MultiIf branches ->
156 MultiIf branches ->
157− do branches' <- forM branches $ \(b,e) -> (,) <$> expression b <*> expression e
157+ do branches' <- forM branches $ \(b,e) -> (,) <$> expression b <*> expression e
158− return $ case last branches of
158+ return $ case last branches of
159− (L _ (Var "Basics.otherwise"), e) -> ifs (init branches') (snd (last branches'))
159+ (L _ (Var "Basics.otherwise"), _) -> safeIfs branches'
160− _ -> ifs branches'
160+ (L _ (Literal (Boolean True)), _) -> safeIfs branches'
161− (obj "_E.If" `call` [ ref "$moduleName", string (show span) ])
161+ _ -> ifs branches' (obj "_E.If" `call` [ ref "$moduleName", string (show span) ])
162− where
162+ where
163+ safeIfs branches = ifs (init branches) (snd (last branches))
163− ifs branches finally = foldr iff finally branches
164+ ifs branches finally = foldr iff finally branches
164− iff (if', then') else' = CondExpr () if' then' else'
165+ iff (if', then') else' = CondExpr () if' then' else'
165
166
166 Case e cases ->
167 Case e cases ->
167 do (tempVar,initialMatch) <- Case.toMatch cases
168 do (tempVar,initialMatch) <- Case.toMatch cases
compiler/Parse/Expression.hs+1−1
@@ -157,7 +157,7 @@ ifExpr = reserved "if" >> whitespace >> (normal <|> multiIf)
157 whitespace <?> "an 'else' branch" ; reserved "else" <?> "an 'else' branch" ; whitespace
157 whitespace <?> "an 'else' branch" ; reserved "else" <?> "an 'else' branch" ; whitespace
158 elseBranch <- expr
158 elseBranch <- expr
159 return $ MultiIf [(bool, thenBranch),
159 return $ MultiIf [(bool, thenBranch),
160− (Location.sameAs elseBranch (Var "otherwise"), elseBranch)]
160+ (Location.sameAs elseBranch (Literal . Literal.Boolean $ True), elseBranch)]
161 multiIf = MultiIf <$> spaceSep1 iff
161 multiIf = MultiIf <$> spaceSep1 iff
162 where iff = do string "|" ; whitespace
162 where iff = do string "|" ; whitespace
163 b <- expr ; padded arrow
163 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"