Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: allow generalization in let #3060

Merged
merged 5 commits into from
Jan 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Lean/Elab/Do.lean
Original file line number Diff line number Diff line change
Expand Up @@ -1368,7 +1368,7 @@ mutual
else
pure doElems.toArray
let contSeq := mkDoSeq contSeq
let auxDo ← `(do let __discr := $val; match __discr with | $pattern:term => $contSeq | _ => $elseSeq)
let auxDo ← `(do match $val:term with | $pattern:term => $contSeq | _ => $elseSeq)
doSeqToCode <| getDoSeqElems (getDoSeq auxDo)

/-- Generate `CodeBlock` for `doReassignArrow; doElems`
Expand Down
20 changes: 16 additions & 4 deletions tests/lean/run/doLetElse.lean
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,22 @@ def foo (x? : Option Nat) : IO Nat := do
IO.println s!"x: {x}"
return x

def test (input : Option Nat) (expected : Nat) : IO Unit := do
def testFoo (input : Option Nat) (expected : Nat) : IO Unit := do
assert! (← foo input) == expected

#eval testFoo (some 10) 10
#eval testFoo none 0
#eval testFoo (some 1) 1

#eval test (some 10) 10
#eval test none 0
#eval test (some 1) 1
def bar (x : Nat) : IO (Fin (x + 1)) := do
let 2 := x | return 0
-- the pattern match performed a substitution
let y : Fin 3 := ⟨1, by decide⟩
return y

def testBar (x : Nat) (expected : Fin (x + 1)) : IO Unit := do
assert! (← bar x) == expected

#eval testBar 1 0
#eval testBar 2 1
#eval testBar 3 0