leanprover-community / leanprover-community/lean

Unknown identifier in `do` block inside tactic mode

Open
#500 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug
Dominant language
C++
Stars
434
Forks
79
PR merge metrics
No merged PRs in 30d

Description

Local variables appearing on the last line of a do block inside tactic mode cause an incorrect "unknown identifier" error:

example (foo bar : list ℤ) : false :=
begin
  have : do { x ← bar, foo } = bar >> foo := rfl, -- unknown identifier 'foo'
  calc do { x ← bar, foo } = bar >> foo : rfl, -- unknown identifier 'foo'
  admit
end

It seems to happen regardless of the tactic used, e.g. writing calc instead of have also causes the same error.

The error only occurs for local names, globals are fine. Also, replacing it with an underscore, or putting the do block in term mode, will work:

example (foo bar : list ℤ) : false :=
begin
  have : do { x ← bar, _ } = bar >> foo := rfl, -- works
  have : do { x ← bar, list.nil } = [] := sorry, -- works
  admit
end

example (foo bar : list ℤ) : false :=
have this : do { x ← bar, foo } = bar >> foo, from rfl, -- works
sorry

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

Reproduce the reported examples in Lean 3, comparing tactic-mode do blocks with the term-mode and global-name cases shown in the issue. Trace the tactic-mode elaboration path for the final local expression; done means local names no longer produce an incorrect unknown-identifier error while the documented working cases remain valid.

Written by the indexing model from the issue text.

Assessment

Domain
compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.