leanprover / leanprover/lean4

Class abbreviations can't be protected

Open
#11,931 0 comments 0 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

Class abbreviations can't be used if they are protected, even from within the containing file.

Context

I needed a class abbreviation, but couldn't think of a concise name for it. I tried to mark it protected to discourage others from relying on it (although of course Lean isn't stable enough for that to really matter anyway), but that prevented me from using it at all.

Steps to Reproduce
namespace X

protected class abbrev ZeroAndOne (α : Type) := Zero α, One α

def zeroOf (α : Type) [ZeroAndOne α] := 0
def oneOf (α : Type) [ZeroAndOne α] := 1

Expected behavior: This typechecks. (It does if protected is removed, or replaced with private.)

Actual behavior: Both attempts to use ZeroAndOne produce the error "invalid binder annotation, type is not a class instance: ?m.2".

Versions

4.28.0-nightly-2026-01-07

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 in the issue and compare its behavior with the same declaration using no modifier or private. Investigate how protected class abbrev is resolved for the two instance annotations. Done means the reproduction typechecks with protected and no longer reports the invalid binder annotation error.

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
Stale
Clarity
Clearly specified
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.