diff --git a/parser-typechecker/src/Unison/Typechecker/Context.hs b/parser-typechecker/src/Unison/Typechecker/Context.hs index 25cadc533..283f79b14 100644 --- a/parser-typechecker/src/Unison/Typechecker/Context.hs +++ b/parser-typechecker/src/Unison/Typechecker/Context.hs @@ -1058,6 +1058,7 @@ annotateLetRecBindings isTop letrec = appendContext $ context (zipWith Ann vs bindingTypes) -- check each `bi` against its type Foldable.for_ (zip bindings bindingTypes) $ \(b, t) -> check b t + ensureGuardedCycle (vs `zip` bindings) -- compute generalized types `gt1, gt2 ...` for each binding `b1, b2...`; -- add annotations `v1 : gt1, v2 : gt2 ...` to the context (_, _, ctx2) <- breakAt (Marker e1) <$> getContext @@ -1069,6 +1070,11 @@ annotateLetRecBindings isTop letrec = appendContext . context $ marker : annotations pure (marker, body, vs `zip` bindingTypesGeneralized) +ensureGuardedCycle :: [(v, Term v loc)] -> M v loc () +ensureGuardedCycle _bindings = pure () + -- todo: require that non-lambdas in the cycle may only depend on lambdas, + -- not on any other non-lambdas + existentialFunctionTypeFor :: (Var v) => Term v loc -> M v loc (Type v loc) existentialFunctionTypeFor lam@(Term.LamNamed' v body) = do v <- extendExistential v diff --git a/unison-src/errors/cyclic-unguarded.u b/unison-src/errors/cyclic-unguarded.u new file mode 100644 index 000000000..f315dfebf --- /dev/null +++ b/unison-src/errors/cyclic-unguarded.u @@ -0,0 +1,13 @@ + +x = y + 1 +y = x + 1 + +> x + +--- + +Currently crashes the runtime with a + +unison: user error (type error, expecting N, got (UninitializedLetRecSlot x in [y,x])) + +