Skip to content

Commit 3a83f2f

Browse files
committed
caseCon: case of error reduces to error
Fixes #109
1 parent f6ffd18 commit 3a83f2f

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

clash-lib/src/CLaSH/Normalize/Transformations.hs

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -241,12 +241,15 @@ caseCon ctx e@(Case subj ty alts)
241241
reduceConstant <- Lens.view evaluator
242242
case reduceConstant tcm True subj of
243243
Literal l -> caseCon ctx (Case (Literal l) ty alts)
244-
subj'@(collectArgs -> (Data _,_)) -> caseCon ctx (Case subj' ty alts)
245-
subj' -> let msg = "Irreducible constant as case subject: " ++ showDoc subj ++ "\nCan be reduced to: " ++ showDoc subj'
246-
in traceIf (lvl > DebugNone) msg $
247-
if lvl > DebugFinal
248-
then error msg
249-
else caseOneAlt e
244+
subj' -> case collectArgs subj' of
245+
(Data _,_) -> caseCon ctx (Case subj' ty alts)
246+
(Prim nm ty',[_,msg])
247+
| nm == "Control.Exception.Base.patError" ->
248+
let e' = mkApps (Prim nm ty') [Right ty,msg]
249+
in changed e'
250+
_ -> traceIf (lvl > DebugNone)
251+
("Irreducible constant as case subject: " ++ showDoc subj ++ "\nCan be reduced to: " ++ showDoc subj')
252+
(caseOneAlt e)
250253

251254
caseCon _ e = caseOneAlt e
252255

0 commit comments

Comments
 (0)