Skip to content

Commit 417cc24

Browse files
committed
fix: bug in instantiateRangeS'
This PR fixes a bug in the function `instantiateRangeS'` in the `Sym` framework.
1 parent d1514f3 commit 417cc24

File tree

2 files changed

+14
-6
lines changed

2 files changed

+14
-6
lines changed

src/Lean/Meta/Sym/InstantiateS.lean

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -56,15 +56,13 @@ It assumes `beginIdx ≤ endIdx` and `endIdx ≤ subst.size`
5656
def instantiateRangeS' (e : Expr) (beginIdx endIdx : Nat) (subst : Array Expr) : AlphaShareBuilderM Expr :=
5757
if _ : beginIdx > endIdx then unreachable! else
5858
if _ : endIdx > subst.size then unreachable! else
59-
let s := beginIdx
6059
let n := endIdx - beginIdx
6160
replaceS' e fun e offset => do
62-
let s₁ := s + offset
6361
match e with
6462
| .bvar idx =>
65-
if _h : idx >= s₁ then
66-
if _h : idx < s₁ + n then
67-
let v := subst[idx - s₁]
63+
if _h : idx >= offset then
64+
if _h : idx < offset + n then
65+
let v := subst[beginIdx + idx - offset]
6866
liftLooseBVarsS' v 0 offset
6967
else
7068
mkBVarS (idx - n)
@@ -73,7 +71,7 @@ def instantiateRangeS' (e : Expr) (beginIdx endIdx : Nat) (subst : Array Expr) :
7371
| .lit _ | .mvar _ | .fvar _ | .const _ _ | .sort _ =>
7472
return some e
7573
| _ =>
76-
if s₁ >= e.looseBVarRange then
74+
if offset >= e.looseBVarRange then
7775
return some e
7876
else
7977
return none
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import Lean
2+
3+
/-- info: (a + 1).add a -/
4+
#guard_msgs in
5+
open Lean Meta Sym in
6+
run_meta SymM.run do
7+
let s₁ ← share <| mkLambda `x .default Nat.mkType (mkApp (mkConst ``Nat.add) (mkNatAdd (mkBVar 0) (mkNatLit 1)))
8+
let s₂ ← share <| mkConst `a
9+
let e ← share <| mkApp2 (mkBVar 1) (mkBVar 0) (mkBVar 0)
10+
logInfo <| (← instantiateRevBetaS e #[s₁, s₂])

0 commit comments

Comments
 (0)