leanprover / leanprover/lean4

`@[ext]` generates highly general theorem patterns without warning

Open
#14,522 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

Prerequisites
Description

Consider:

import Lean

open Lean Meta

class Injects (H : Type u) (X : outParam (Type v)) where
  coe : H → X
  injective : Function.Injective coe

@[ext] theorem Injects.ext {H : Type u} {X : Type v} [Injects H X]
    {a b : H} (h : Injects.coe a = Injects.coe b) : a = b := Injects.injective h


structure Foo where
  x : BitVec 8

#eval Ext.getExtTheorems (mkConst ``Foo)

This returns Injects.ext because it is a theorem that can apply to any type in principle and thus has a * discr tree key. The only way to know is to run the Injects TC query. Arguably this is a potentially dangerous lemma to register.

Expected behavior: ext should warn or refuse to register the theorem

Actual behavior: the theorem is silently accepted

Versions

Lean 4.34.0-nightly-2026-07-22

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 reproduction using @[ext], Ext.getExtTheorems, and the Injects.ext theorem after importing Lean. Trace how the ext attribute registers theorem patterns and how the discrimination-tree key is chosen. Done means the overly general theorem is warned about or refused, with the reproduction covered by a regression test.

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
52/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.