leanprover / leanprover/lean4

Incorrect transparency used to expose differences

Open
#14,143 0 comments 3 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

Prerequisites
Description

In pretty much all uses of addPPExplicitToExposeDiff, the isDefEq calls nested in addPPExplicitToExposeDiff run under the wrong transparency, namely, always on default transparency. This causes some unfortunate error messages where two different expressions (under e.g. reducible transparency) are shown with the exact same pretty-printing even after addPPExplicitToExposeDiff.

Context

Report by someone on discord.

Steps to Reproduce
class MyClass (α : Type) where
  data : Nat

-- make a diamond
instance inst1 : MyClass Nat where data := 3
instance inst2 : MyClass Nat where data := id 3

/--
error: Tactic `rfl` failed: The left-hand side
  @id Nat (MyClass.data Nat)
is not definitionally equal to the right-hand side
  @id Nat (MyClass.data Nat)

⊢ id (MyClass.data Nat) = id (MyClass.data Nat)
-/
#guard_msgs in
example : id inst1.data = id inst2.data := by
  with_reducible rfl

Expected behavior:
Under reducible transparency, the two MyClass.data calls are not defeq, namely, the instance arguments are not equivalent under with_reducible_and_instances. Thus, this difference should be exposed by writing:

The left-hand side
  @id Nat (@MyClass.data Nat inst1)
is not definitionally equal to the right-hand side
  @id Nat (@MyClass.data Nat inst2)

Actual behavior:
The defeq check failed but the pretty-printed versions are exactly the same.

Versions

Lean 4.33.0, commit 75591856794182559e5a3713bdf8aa00c52fc7ca

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 addPPExplicitToExposeDiff entry point and inspect its nested isDefEq calls, using the minimal Lean reproduction and its with_reducible context as the test case. Done means the #guard_msgs output exposes the distinct inst1 and inst2 instance arguments instead of printing identical expressions.

Written by the indexing model from the issue text.

Assessment

Domain
compilers
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
52/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.