About: highInferredUniverse
This error message appears when Lean's elaboration algorithm is about to assign a new type to a higher universe than may be necessary.
Constructor argument universe levels must be no greater than the resulting universe level, so given this definition:
inductive MaybeTwo (α : Type u)
| none
| some (fst snd : α)
then the universe for MaybeTwo α must be Type u or higher.
Lean automatically infers the universe to be the least universe, hence it chooses Type u, or, equivalently,
Sort (u + 1). (See the reference guide to Universes for more
details on the relationship between Prop, Sort, and Type.)
There are certain situations where universe inference yields a universe level that may be higher than it could be. In these situations, Lean chooses to avoid silently accepting this unnecessarily high universe level, because unnecessarily high universe levels can cause hard-to-diagnose errors in later definitions. Avoiding these situations requires an explicitly provided universe for the inductive type using a universe level in a slightly different form. This can't currently be done automatically, so fixing it requires user intervention.
Examples
Use of `Type` May Force Universe Too High
structure MyPair (α β : Sort u) : Type _ where
(a : α)
(b : β)
structure MyPair (α β : Sort u) where
(a : α)
(b : β)
structure MyPair (α β : Sort u) : Sort (max 1 u) where
(a : α)
(b : β)
structure MyPair (α β : Type u) : Type _ where
(a : α)
(b : β)
structure MyPair (α β : Sort u) : Type u where
(a : α)
(b : β)
The initial type annotation Type _ forces MyPair into a universe that looks like
Sort (_ + 1), but the best universe for MyPair is Sort (max u 1). (See the section
on Prop vs Type for why it is Sort (max u 1) and not just
Sort u.)
The first two fixes are all equivalent, and allow MyPair to have any non-zero universe that
is larger than u. The last two fixes make MyPair less general, but also silence the error.
Inductive Definition Needs Sort Annotations
In this case, the error message is a false positive, but the issue can be easily fixed with
clarifying annotations. After annotating Foo with a universe u, the overall type can be assigned
type that the error message suggests, which silences the error.