Zulip Chat Archive
Stream: general
Topic: cryptic error
Jon Eugster (Jun 05 2024 at 13:36):
I've come across a user mistake which corresponds to the following MWE:
#check (1 : ∀ (n : Nat), True) -- error: invalid universe level, ?u.5 is not greater than 0
Writing 1 :
here is nonsense, but does somebody understand why the error messages says what it says? Why is it about universes?
Shreyas Srinivas (Jun 05 2024 at 13:38):
It says that the universe of your type is 0 I.e. you have a Prop.
Yaël Dillies (Jun 05 2024 at 13:38):
Is it trying to apply docs#Pi.instOne and failing to unify f : ι → Type v₁
with fun _ : Nat ↦ True
?
Shreyas Srinivas (Jun 05 2024 at 13:44):
Yaël Dillies said:
Is it trying to apply docs#Pi.instOne and failing to unify
f : ι → Type v₁
withfun _ : Nat ↦ True
?
Would that also cause the same error on #check (2 : ∀ (n : Nat), True)
Shreyas Srinivas (Jun 05 2024 at 13:45):
I think basically it complains because you are giving it a value that is data, which is at least universe 1 or higher and the type is a Prop
Shreyas Srinivas (Jun 05 2024 at 13:47):
I am guessing that the part of the typechecker that performs universe unification runs early into typechecking, but I could be wrong.
Shreyas Srinivas (Jun 05 2024 at 13:50):
My guess is wrong. This produces a normal type error :
#check ("some_string": ∀ (n : Nat), True)
Jon Eugster (Jun 05 2024 at 13:55):
Yaël Dillies said:
Is it trying to apply docs#Pi.instOne and failing to unify
f : ι → Type v₁
withfun _ : Nat ↦ True
?
That's not quite it, because it's also triggered without import Mathlib
the following snippet shows that the error message from docs#One are a bit better:
import Mathlib
/-
application type mismatch
One (ℕ → True)
argument
ℕ → True
has type
Prop : Type
but is expected to have type
Type ?u.1 : Type (?u.1 + 1)
-/
#synth One <| (∀ (n : Nat), True)
The error invalid universe level, {u} is not greater than 0
comes apparently from docs#Lean.Meta.decLevel core
Shreyas Srinivas (Jun 05 2024 at 13:55):
A little more debugging later:
import Qq
import Lean
open Qq Lean Meta
#check (1 : ∀ (n : Nat), True) -- error: invalid universe level, ?u.5 is not greater than 0
#eval q(1 : ∀ (n : Nat), True) -- produces the message below
Lean.Expr.app
(Lean.Expr.app
(Lean.Expr.const `sorryAx [Lean.Level.zero])
(Lean.Expr.forallE
Lean.Name.anonymous
(Lean.Expr.const `Nat [])
(Lean.Expr.const `True [])
(Lean.BinderInfo.default)))
(Lean.Expr.const `Bool.true [])
Jon Eugster (Jun 05 2024 at 13:55):
Thanks for the insight, both of you!
Shreyas Srinivas (Jun 05 2024 at 13:56):
Lean is interpreting the EDIT: 1
as a level expression for some unknown reason.
My mistake. I was looking at this ((Lean.Expr.const sorryAx [Lean.Level.zero])
)
Jon Eugster (Jun 05 2024 at 14:12):
Ah I understand now:
Writing 1
triggers docs#Lean.Elab.Term.elabNumLit and on this line in core this calls docs#Lean.Meta.getDecLevel with an expected type of level 0
thus it triggers the error.
Shreyas Srinivas (Jun 05 2024 at 14:30):
And this doesn't happen with strings because elabStrLit
directly calls mkStrLit
?
Shreyas Srinivas (Jun 05 2024 at 14:41):
What is passed to the expectedType?
parameter of elabNumLit
here?
Jon Eugster (Jun 05 2024 at 15:29):
Shreyas Srinivas said:
And this doesn't happen with strings because
elabStrLit
directly callsmkStrLit
?
What is passed to theexpectedType?
parameter ofelabNumLit
here?
Looks like it. I think expectedType?
here is some (Nat → True)
.
FWIW I've create a PR lean4#4366 which adds a more verbose error message.
Shreyas Srinivas (Jun 05 2024 at 16:24):
Could the error message also show the expected type?
Jon Eugster (Jun 05 2024 at 20:35):
it could, I just didnt know how to do that without either an additional match
statement or a superfluous some
floating around.
Do you have a suggestion for the ideal wording? Kyle made a very good suggestion, as always :)
Shreyas Srinivas (Jun 06 2024 at 09:35):
Oh. I don't see Kyle's suggestion, but I do see that Leo added more fine grained error reporting
Jon Eugster (Jun 06 2024 at 09:45):
Indeed that was way fast of Leo :octopus:
Last updated: May 02 2025 at 03:31 UTC