Skip to content

Commit 50382b8

Browse files
committed
Get letrec bindings working in functions
1 parent 21e4959 commit 50382b8

File tree

1 file changed

+7
-3
lines changed
  • parser-typechecker/src/Unison/Typechecker

1 file changed

+7
-3
lines changed

parser-typechecker/src/Unison/Typechecker/Context.hs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ import Unison.Typechecker.TypeLookup qualified as TL
105105
import Unison.Typechecker.TypeVar qualified as TypeVar
106106
import Unison.Var (Var)
107107
import Unison.Var qualified as Var
108+
import qualified Unison.Debug as Debug
108109

109110
type TypeVar v loc = TypeVar.TypeVar (B.Blank loc) v
110111

@@ -1922,6 +1923,8 @@ annotateLetRecBindings span isTop letrec =
19221923
gen bindingType _arity = generalizeExistentials ctx2 bindingType
19231924
bindingTypesGeneralized = zipWith gen bindingTypes bindingArities
19241925
annotations = zipWith Ann vs bindingTypesGeneralized
1926+
-- for_ (zip3 vs bindings bindingTypesGeneralized) \(v, b, t) -> do
1927+
-- noteBinding v (loc b) (TypeVar.lowerType t)
19251928
appendContext annotations
19261929
pure (body, vs `zip` bindingTypesGeneralized)
19271930

@@ -2460,7 +2463,7 @@ checkWanted want (Term.Lam' body) (Type.Arrow'' i es o) = do
24602463
body <- pure $ ABT.bindInheritAnnotation body (Term.var () x)
24612464
checkWithAbilities es body o
24622465
pure want
2463-
checkWanted want (Term.Let1Top' top binding m) t = do
2466+
checkWanted want abt@(Term.Let1Top' top binding m) t = do
24642467
(tbinding, wbinding) <- synthesizeBinding top binding
24652468
want <- coalesceWanted wbinding want
24662469
v <- ABT.freshen m freshenVar
@@ -2469,14 +2472,15 @@ checkWanted want (Term.Let1Top' top binding m) t = do
24692472
-- enforce that actions in a block have type ()
24702473
subtype tbinding (DDB.unitType (ABT.annotation binding))
24712474
extendContext (Ann v tbinding)
2475+
-- Need to somehow fix the annotation on these
2476+
Debug.debugM Debug.Temp "checkWanted" $ (v, binding)
2477+
noteBinding v (ABT.annotation abt) (TypeVar.lowerType tbinding)
24722478
checkWanted want (ABT.bindInheritAnnotation m (Term.var () v)) t
24732479
checkWanted want (Term.LetRecNamed' [] m) t =
24742480
checkWanted want m t
24752481
-- letrec can't have effects, so it doesn't extend the wanted set
24762482
checkWanted want abt@(Term.LetRecTop' isTop lr) t =
24772483
markThenRetractWanted (Var.named "let-rec-marker") $ do
2478-
-- TODO: I don't think we want to emit types for local bindings from here, but will need
2479-
-- to refactor to do that properly
24802484
e <- annotateLetRecBindings (ABT.annotation abt) isTop lr
24812485
checkWanted want e t
24822486
checkWanted want e@(Term.Match' scrut cases) t = do

0 commit comments

Comments
 (0)