lean4-htt/tests/elab/issue12768.lean
Sebastian Graf cbda692e7e
fix: free variable in do bind when continuation type depends on bvar (#13396)
This PR fixes #12768, where the new `do` elaborator produced a
"declaration has free variables" kernel error when the bind
continuation's result type was definitionally but not syntactically
independent of the bound variable. The fix moves creation of the result
type metavariable before `withLocalDecl`, so the unifier must reduce
away the dependency.

For example, given `def Quoted (x : Nat) := Nat`, the expression `do let
val ← pure 3; withStuff val do return 3` would fail because `β` was
assigned `Quoted val` rather than `Nat`.
2026-04-13 18:51:45 +00:00

13 lines
284 B
Text

module
set_option backward.do.legacy false
set_option linter.unusedVariables.funArgs false in
def Quoted (x : Nat) := Nat
def withStuff (x : Nat) (f : IO (Quoted x)) : IO (Quoted x) := f
def myFunc : IO Nat := do
let val : Nat ← pure 3
withStuff val do
return (3 : Nat)