Skip to content

Commit

Permalink
Fix bug in failing match in 'do'.
Browse files Browse the repository at this point in the history
  • Loading branch information
lennart-augustsson-epicgames committed Feb 4, 2024
1 parent cfe4eb0 commit c9fd045
Show file tree
Hide file tree
Showing 6 changed files with 11,694 additions and 11,652 deletions.
23,309 changes: 11,668 additions & 11,641 deletions generated/mhs.c

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions lib/Control/Monad/State/Strict.hs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ module Control.Monad.State.Strict(
) where
import Prelude
import Control.Monad
import Control.Monad.Fail

data State s a = S (s -> (a, s))

Expand All @@ -27,6 +28,8 @@ instance forall s . Monad (State s) where
(>>) = (*>)
return = pure

instance forall s . MonadFail (State s)

runState :: forall s a . State s a -> (s -> (a,s))
runState (S x) = x

Expand Down
5 changes: 2 additions & 3 deletions lib/Numeric.hs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ module Numeric(
import Primitives
import Control.Error
import Control.Monad
import Control.Monad.Fail
import Data.Bool
import Data.Char
import Data.Eq
Expand Down Expand Up @@ -58,9 +59,7 @@ readSigned readPos = readParen False read'
read' :: ReadS a
read' r = readPos r ++
do
-- XXX compiler broken ('-',s) <- lex r
(c,s) <- lex r
guard (c == '-')
('-',s) <- lex r
(x, t) <- readPos s
return (- x, t)

Expand Down
9 changes: 3 additions & 6 deletions lib/Text/Read.hs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ module Text.Read(
import Primitives
import Control.Error
import Control.Monad
import Control.Monad.Fail
import Data.Char
import Data.Bool_Type
import Data.Eq
Expand Down Expand Up @@ -44,13 +45,9 @@ readParen b g =
optional r = g r ++ mandatory r
mandatory :: ReadS a
mandatory r = do
-- XXX compiler broken ('(',s) <- lex r
(lp,s) <- lex r
guard (lp == '(')
('(',s) <- lex r
(x,t) <- optional s
-- (')',u) <- lex t
(rp,u) <- lex t
guard (rp == ')')
(')',u) <- lex t
return (x,u)

-- Really bad lexer
Expand Down
19 changes: 17 additions & 2 deletions src/MicroHs/TypeCheck.hs
Original file line number Diff line number Diff line change
Expand Up @@ -1116,7 +1116,10 @@ expandClass dcls@(Class ctx (iCls, vks) fds ms) = do
expandClass d = return [d]

simpleEqn :: Expr -> [Eqn]
simpleEqn e = [Eqn [] $ EAlts [([], e)] []]
simpleEqn e = [Eqn [] $ simpleAlts e]

simpleAlts :: Expr -> EAlts
simpleAlts e = EAlts [([], e)] []

-- Keep the list empty if there are no fundeps
mkIFunDeps :: [Ident] -> [FunDep] -> [IFunDep]
Expand Down Expand Up @@ -1486,8 +1489,13 @@ tcExprR mt ae =
ibind = mkIdentSLoc loc ">>="
sbind = maybe ibind (\ mn -> qualIdent mn ibind) mmn
x = eVarI loc "$b"
patAlt = [(p, simpleAlts $ EDo mmn ss)]
failMsg s = EApp (EVar (mkIdentSLoc loc "fail")) (ELit loc (LStr s))
failAlt =
if failureFree p then []
else [(EVar dummyIdent, simpleAlts $ failMsg "bind")]
tcExpr mt (EApp (EApp (EVar sbind) a)
(eLam [x] (ECase x [(p, EAlts [([], EDo mmn ss)] [])])))
(eLam [x] (ECase x (patAlt ++ failAlt))))
SThen a -> do
let
ithen = mkIdentSLoc loc ">>"
Expand Down Expand Up @@ -1572,6 +1580,13 @@ tcExprR mt ae =
_ -> error $ "tcExpr: cannot handle: " ++ show (getSLoc ae) ++ " " ++ show ae
-- impossible

-- Approximation if failure free
failureFree :: EPat -> Bool
failureFree (EVar _) = True
failureFree (ETuple ps) = all failureFree ps
failureFree (ESign p _) = failureFree p
failureFree _ = False

eSetFields :: EField -> Expr -> Expr
--eSetFields ([i], e) r = eSetField (i, e) r
eSetFields (EField is e) r =
Expand Down
1 change: 1 addition & 0 deletions tests/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ test:
$(TMHS) Record && $(EVAL) > Record.out && diff Record.ref Record.out
$(TMHS) Deriving && $(EVAL) > Deriving.out && diff Deriving.ref Deriving.out
$(TMHS) Unicode && $(EVAL) > Unicode.out && diff Unicode.ref Unicode.out
$(TMHS) BindPat && $(EVAL) > BindPat.out && diff BindPat.ref BindPat.out

errtest:
sh errtester.sh < errmsg.test
Expand Down

0 comments on commit c9fd045

Please sign in to comment.