@@ -183,10 +183,10 @@ jsCon :: JS
183183jsCon = JSRaw $ idrRTNamespace ++ "Con"
184184
185185jsTag :: JS -> JS
186−jsTag obj = (JSProj obj "tag")
186+jsTag obj = JSProj obj "tag"
187187
188188jsTypeTag :: JS -> JS
189−jsTypeTag obj = (JSProj obj "type")
189+jsTypeTag obj = JSProj obj "type"
190190
191191jsBigInt :: JS -> JS
192192jsBigInt val =
@@ -614,7 +614,7 @@ translateExpression patterncase
614614 where
615615 caseHelper var cases param =
616616 JSApp (JSFunction [param] (
617− JSCond $ map ((expandCase param) . translateCase param) cases
617+ JSCond $ map (expandCase param . translateCaseCond param) cases
618618 )) [JSVar var]
619619
620620 expandCase :: String -> (Cond, JS) -> (JS, JS)
@@ -655,11 +655,11 @@ data CaseType = ConCase Int
655655data Cond = CaseCond CaseType
656656 | RawCond JS
657657
658−translateCase :: String -> SAlt -> (Cond, JS)
659−translateCase _ (SDefaultCase e) =
660− (CaseCond DefaultCase, translateExpression e)
658+translateCaseCond :: String -> SAlt -> (Cond, JS)
659+translateCaseCond _ cse@(SDefaultCase _) =
660+ (CaseCond DefaultCase, translateCase Nothing cse)
661661
662−translateCase var (SConstCase ty e)
662+translateCaseCond var cse@(SConstCase ty _)
663663 | StrType <- ty = matchHelper JSStringTy
664664 | PtrType <- ty = matchHelper JSPtrTy
665665 | Forgot <- ty = matchHelper JSForgotTy
@@ -669,20 +669,24 @@ translateCase var (SConstCase ty e)
669669 | (AType (ATInt ITChar)) <- ty = matchHelper JSCharTy
670670 where
671671 matchHelper :: JSType -> (Cond, JS)
672− matchHelper ty = (CaseCond $ TypeCase ty, translateExpression e)
672+ matchHelper ty = (CaseCond $ TypeCase ty, translateCase Nothing cse)
673673
674−translateCase var (SConstCase cst@(BI _) e) =
674+translateCaseCond var cse@(SConstCase cst@(BI _) _) =
675675 let cond = jsMeth (JSRaw var) "equals" [translateConstant cst] in
676− (RawCond cond, translateExpression e)
676+ (RawCond cond, translateCase Nothing cse)
677677
678−translateCase var (SConstCase cst e) =
678+translateCaseCond var cse@(SConstCase cst _) =
679679 let cond = JSRaw var `jsEq` translateConstant cst in
680− (RawCond cond, translateExpression e)
680+ (RawCond cond, translateCase Nothing cse)
681681
682−translateCase var (SConCase a tag name vars e) =
682+translateCaseCond var cse@(SConCase _ tag _ _ _) =
683+ (CaseCond $ ConCase tag, translateCase (Just var) cse)
684+
685+translateCase :: Maybe String -> SAlt -> JS
686+translateCase _ (SDefaultCase e) = translateExpression e
687+translateCase _ (SConstCase _ e) = translateExpression e
688+translateCase (Just var) (SConCase a _ _ vars e) =
683689 let params = map jsVar [a .. (a + length vars)] in
684− (CaseCond $ ConCase tag,
685− jsMeth (JSFunction params (JSReturn $ translateExpression e)) "apply" [
686− JSThis, JSProj (JSRaw var) "vars"
687− ]
688− )
690+ jsMeth (JSFunction params (JSReturn $ translateExpression e)) "apply" [
691+ JSThis, JSProj (JSRaw var) "vars"
692+ ]