leanprover / leanprover/lean4

The inferred level for structures doesn't always work

Open
#13,473 1 comment 0 reactions 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

The inferred level for structures can cause universe level comparison failures when imax is involved and sometimes it's quite hard to find a working level.

Context

Figuring out dependent mutual wellfounded recursion.

Steps to Reproduce
/--
error: Invalid universe level for field `MyType`: Field has type
  Sort (imax u v)
at universe level
  (imax u v) + 1
which is not less than or equal to the structure's resulting universe level
  max (u + 1) (v + 1)
-/
#guard_msgs in
structure Test where
  MyType : Sort (imax u v)
  thing : MyType

Expected behavior:
The inferred level works for any non-recursive structures.

Actual behavior:
Test fails with an error at the field MyType. Specifying Type (imax u v) manually produces the error [...] imax u v [...] is not less than or equal to [...] (imax u v) + 1 at thing. Another option, Sort (max (imax u v + 1) (imax 2 (imax u v))), instead produces a kernel error. Sort (max (imax u v + 1) u v) works but it should not be so hard to find a working level.

Versions

Lean 4.31.0-nightly-2026-04-17

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 by running the minimal structure example against the latest Lean nightly or on live.lean-lang.org and inspect the structure universe-level inference path, focusing on the imax case. Done means the reproducible non-recursive structure is accepted without manually specifying a level, with a regression test covering the example.

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.