leanprover / leanprover/lean4

bug: `specialize` tactic is missing an occurs check

Open
#2,506 4 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

Prerequisites
  • Put an X between the brackets on this line if you have done all of the following:
    • Checked that your issue isn't already filed.
    • Reduced the issue to a self-contained, reproducible test case.
Description

The tactic specialize does not check to see if the main goal occurs in the value that to which it assigns the main goal. This causes a stack overflow:

open Lean Meta Elab Tactic in
/-- `rename_main_goal a` renames the main goal to `a`. -/
elab "rename_main_goal " n:ident : tactic => do
  let g ← getMainGoal
  g.setUserName n.getId

example (h : True → True) : True := by
  rename_main_goal a
  specialize h ?a -- stack overflow
Steps to Reproduce
  1. Obtain a goal and a hypothesis in that goal's context which has an argument of the same type as the goal.
  2. With that goal as the main goal, specialize the hypothesis applied to that goal.

Expected behavior: An error pointing out that the goal occurs in the specialized value.

Actual behavior: Stack overflow

Reproduces how often: Always

Versions

4.0.0-rc4; macOS Ventura 13.4.1 (Intel-based)

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 running the self-contained reproducer in the issue and inspect the specialize tactic entry point and its goal-assignment path. Confirm that applying the main goal produces an error about the goal occurring in the specialized value rather than a stack overflow, then add or run a regression test for the example.

Written by the indexing model from the issue text.

Assessment

Domain
compilers, tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.