~jojo/Carth

ef8e4e0f9f6c7d414dd2d4070d6f4e3c0b269a3a — JoJo 1 year, 10 months ago 8e8ef5c
Fix fun-match globals not allowed to be recursive

;; This was and should be allowed
(define (foo x) (foo x))

;; This was and should be disallowed
(define foo foo)

;; This was disallowed, but should be allowed
(define foo
  (fun-match
    ((case x
           (foo (deref x))))))
2 files changed, 6 insertions(+), 5 deletions(-)

M src/Ast.hs
M src/Infer.hs
M src/Ast.hs => src/Ast.hs +4 -3
@@ 23,7 23,7 @@ module Ast
    , Extern(..)
    , Program(..)
    , startType
    , isFun
    , isFunLike
    )
where



@@ 370,7 370,8 @@ idstr (Id (WithPos _ x)) = x
startType :: Type
startType = TFun (TPrim TUnit) (TPrim TUnit)

isFun :: Expr -> Bool
isFun (WithPos _ e) = case e of
isFunLike :: Expr -> Bool
isFunLike (WithPos _ e) = case e of
    Fun _ _ -> True
    FunMatch _ -> True
    _ -> False

M src/Infer.hs => src/Infer.hs +2 -2
@@ 22,7 22,7 @@ import FreeVars
import Subst
import NonEmpty
import qualified Ast
import Ast (Id(..), IdCase(..), idstr, scmBody, isFun)
import Ast (Id(..), IdCase(..), idstr, scmBody, isFunLike)
import TypeErr
import AnnotAst hiding (Id)
import Match


@@ 129,7 129,7 @@ inferDefsComponents = \case
                (\(mayscm, t) -> fromMaybe (Forall Set.empty t) mayscm)
                (zip mayscms' ts)
        forM_ (zip idents bodies) $ \(Id name, body) ->
            when (not (isFun body) && isCyclic)
            when (not (isFunLike body) && isCyclic)
                $ throwError (RecursiveVarDef name)
        bodies' <-
            withLocals (zip names scms)