leanprover / leanprover/lean4

bug: stuck at solving universe constraint "while trying to unify `α : Type u` with `α : Type u`" message

Open
#7,799 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

Please put an X between the brackets as you perform the following steps:

Description

The error message that is shown when universe unification does not make sense in some cases.

Steps to Reproduce

Run this in Lean 4 Web:

inductive Y (α' β) where
| y : α' → β → Y α' β

def predicate {α' β} :
  Y.{u + 1, v + 1} α' β → Prop := sorry

def weird_cast {α'' α' : Type u} (x : α'') : α' :=
  sorry

example {α : Type u} {x : α} (h : predicate (weird_cast x)) :
    Unit := ()

(I know, the example is really contrived. This is due to the minimization.)

Expected behavior:

The code is obviously underdetermined (and nonsensical). It compiles after passic explicit arguments (β := α) (α := α) to predicate.

I imagine the error message should describe the failure to determine α, β or α first. As long as they are undetermined, this seems to be the more instructive kind of error than a universe unification error.

If a universe unification error needs to be shown, it should clearly indicate what is being unified and why it fails. The user should be convinced from the error message that there's a problem.

Actual behavior:

I get this error message:

stuck at solving universe constraint
  max ?u.520 ?u.521 =?= u
while trying to unify
  α : Type u
with
  α : Type u

I find it confusing because α : Type u should definitely unify with itself, and it certainly has nothing to do with the maximum of two level metavariables.

Versions
Lean 4.19.0-rc2
Target: x86_64-unknown-linux-gnu

using Lean 4 Web.

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 example in Lean 4 Web and compare the reported universe constraint with the expected underdetermined implicit arguments. Trace the diagnostic path for universe unification and implicit-argument elaboration. Done means the example reports the unresolved arguments clearly, or explains the actual failed constraint in terms users can understand.

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
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.