fix: bug at isDefEqOffset

fixes #326
This commit is contained in:
Leonardo de Moura 2021-03-02 17:22:22 -08:00
parent 12e9d1f7d2
commit f1245f9dc7
2 changed files with 17 additions and 2 deletions

View file

@ -21,7 +21,7 @@ private abbrev withInstantiatedMVars (e : Expr) (k : Expr → OptionT MetaM α)
partial def evalNat : Expr → OptionT MetaM Nat
| Expr.lit (Literal.natVal n) _ => return n
| Expr.mdata _ e _ => evalNat e
| Expr.const `Nat.zero _ _ => return 0
| Expr.const `Nat.zero .. => return 0
| e@(Expr.app ..) => visit e
| e@(Expr.mvar ..) => visit e
| _ => failure
@ -137,7 +137,8 @@ private def mkOffset (e : Expr) (offset : Nat) : MetaM Expr := do
def isDefEqOffset (s t : Expr) : MetaM LBool := do
let ifNatExpr (x : MetaM LBool) : MetaM LBool := do
let type ← inferType s
if (← Meta.isExprDefEqAux type (mkConst ``Nat)) then
-- Remark: we use `withNewMCtxDepth` to make sure we don't assing metavariables when performing the `isDefEq` test
if (← withNewMCtxDepth <| Meta.isExprDefEqAux type (mkConst ``Nat)) then
x
else
return LBool.undef

14
tests/lean/run/326.lean Normal file
View file

@ -0,0 +1,14 @@
abbrev Zero α := OfNat α (natLit! 0)
class Monoid (α : Type u) [Zero α] extends Add α where
zero_add (a : α) : 0 + a = a
add_zero (a : α) : a + 0 = a
attribute [simp] Monoid.zero_add Monoid.add_zero
variable {α : Type u} [Zero α] [Monoid α]
-- works
example (a : α) : 0 + a = a := by simp
example (a : α) : a + 0 = a := by simp