Skip to content

Commit b92da23

Browse files
committed
fix: simp argument elaboration metacontext depth
This PR fixes an issue where pre-existing metavariables in simp arguments would be abstracted, which could lead to type-incorrect simp lemmas. Closes #9286.
1 parent ac0b829 commit b92da23

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

src/Lean/Elab/Tactic/Simp.lean

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ private def elabDeclToUnfoldOrTheorem (config : Meta.ConfigWithKey) (id : Origin
204204

205205
private def elabSimpTheorem (config : Meta.ConfigWithKey) (id : Origin) (stx : Syntax)
206206
(post : Bool) (inv : Bool) : TermElabM ElabSimpArgResult := do
207-
let thm? ← Term.withoutModifyingElabMetaStateWithInfo <| withRef stx do
207+
let thm? ← Term.withoutModifyingElabMetaStateWithInfo <| withNewMCtxDepth <| withRef stx do
208208
let e ← Term.elabTerm stx .none
209209
Term.synthesizeSyntheticMVars (postpone := .no) (ignoreStuckTC := true)
210210
let e ← instantiateMVars e

tests/lean/run/9286.lean

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/-!
2+
# Test for issue 9286
3+
https://github.com/leanprover/lean4/issues/9286
4+
5+
Previously `simp` would create a type incorrect term.
6+
The proximal issue was that the universe level metavariable in the type `a` was being
7+
abstracted without abstracting `a` itself.
8+
However, we should not be abstracting `a`; instead, simp arguments should be elaborated
9+
with a new metacontext depth -- this is in part justified by the fact that elaboration
10+
of simp arguments should not be assigning metavariables.
11+
-/
12+
13+
inductive SomeThing.{u} : Prop where
14+
| mk (_ : PUnit.{u})
15+
16+
/-!
17+
Previously `simp` would succeed and lead to a kernel typechecking error.
18+
Now, `simp` correctly makes no progress.
19+
-/
20+
/-- error: `simp` made no progress -/
21+
#guard_msgs in
22+
set_option pp.universes true in
23+
def testMe (a : PUnit) : PLift SomeThing := by
24+
constructor
25+
have := SomeThing.mk a
26+
simp only [SomeThing.mk a]

0 commit comments

Comments
 (0)