leanprover / leanprover/lean4

"found messy" can break proof irrelevance in `isDefEq`

Open
#13,170 2 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

Prerequisites
Description

isDefEqs "found messy" handling can cause proof arguments to be compared

Context

This causes several cases of the anti-pattern simp; rfl in byte array files.

Steps to Reproduce
class MyClass (f : outParam (Nat → Nat)) where

def test (f : outParam (Nat → Nat)) [MyClass f] (h : f 0 < 2) : Bool :=
  match f 0, h with
  | 0, _ => false
  | 1, _ => true

/--
error: Tactic `rfl` failed: equality lhs
  test f h₁
is not definitionally equal to rhs
  test f h₂

f : Nat → Nat
inst✝ : MyClass f
h₁ : f 0 < 2
h₂ : f 0 + 1 ≤ 2
⊢ test f h₁ = test f h₂
---
trace: [Meta.isDefEq] ❌️ test f h₁ =?= test f h₂
  [Meta.isDefEq] found messy f =?= f
  [Meta.isDefEq] found messy h₁ =?= h₂
  [Meta.isDefEq] ✅️ inst✝ =?= inst✝
  [Meta.isDefEq] ✅️ f =?= f
  [Meta.isDefEq] ❌️ h₁ =?= h₂
    [Meta.isDefEq] ❌️ f 0 < 2 =?= f 0 + 1 ≤ 2
      [Meta.isDefEq] ❌️ @LT.lt =?= @LE.le
      [Meta.isDefEq.onFailure] ❌️ f 0 < 2 =?= f 0 + 1 ≤ 2
      [Meta.isDefEq] ❌️ (f 0).lt 2 =?= (f 0 + 1).le 2
        [Meta.isDefEq] ❌️ Nat.lt =?= Nat.le
        [Meta.isDefEq.onFailure] ❌️ (f 0).lt 2 =?= (f 0 + 1).le 2
        [Meta.isDefEq.onFailure] ❌️ (f 0).lt 2 =?= (f 0 + 1).le 2
  [Meta.isDefEq.onFailure] ❌️ test f h₁ =?= test f h₂
  [Meta.isDefEq.onFailure] ❌️ test f h₁ =?= test f h₂
-/
#guard_msgs in
example (f : outParam (Nat → Nat)) [MyClass f] (h₁ : f 0 < 2) (h₂ : f 0 + 1 ≤ 2) : test f h₁ = test f h₂ := by
  set_option trace.Meta.isDefEq true in
  with_reducible eq_refl

Expected behavior: Just like usual, isDefEq ignores all proof arguments and succeeds.

Actual behavior: isDefEq found messy and compares the two proofs h₁ and h₂, which amounts to comparing the types. However, this fails under reducible transparency.

Versions

Lean 4.30.0-nightly-2026-03-28

Impact

Add 👍 to issues you consider important. If others are impacted by this issue, please ask them to add 👍 to it.

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 with the minimal MyClass/test example and inspect the Meta.isDefEq trace, especially the found messy handling. Follow the isDefEq path that compares test f h₁ with test f h₂; done means proof arguments are ignored and the example succeeds under reducible transparency without comparing h₁ and h₂.

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
Quiet
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.