leanprover / leanprover/lean4

Parse issue involving try-catch-catch

Open
#8,220 1 comment 10 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug do-notation P-medium
Dominant language
Lean
Stars
9.2k
Forks
990
Avg merge
1d 17h
Merged PRs (30d)
175

Description

example : IO Unit := do
  try
    for _ in [1] do
      try
        pure ()
      catch _ => unreachable!
  catch _ => unreachable!

produces the error invalid `try`, it must have a `catch` or `finally` , tested on 4.20.0-rc2. It appears the issue is that it is parsed as a try-catch-catch block like this:

example : IO Unit := do
  try
    for _ in [1] do
      try
        pure ()
      catch _ => unreachable!
      catch _ => unreachable!

and so the first try is left orphaned. (Are multiple catch blocks like this actually used in practice? I would not expect this to be legal even without the weird indentation.)

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the example with Lean 4.20.0-rc2 and inspect how the parser handles the nested try and catch indentation. Confirm the intended parsing behavior, then verify that the example no longer produces the invalid-try error and that multiple catch blocks remain handled appropriately.

Written by the indexing model from the issue text.

Assessment

Domain
compilers
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.