lean4-htt/tests/lean/run/inductive_univ.lean
Kyle Miller a19ff61e15
feat: allow structure in mutual blocks (#6125)
This PR adds support for `structure` in `mutual` blocks, allowing
inductive types defined by `inductive` and `structure` to be mutually
recursive. The limitations are (1) that the parents in the `extends`
clause must be defined before the `mutual` block and (2) mutually
recursive classes are not allowed (a limitation shared by `class
inductive`). There are also improvements to universe level inference for
inductive types and structures. Breaking change: structure parents now
elaborate with the structure in scope (fix: use qualified names or
rename the structure to avoid shadowing), and structure parents no
longer elaborate with autoimplicits enabled.

Internally, this is a large refactor of both the `inductive` and
`structure` commands. Common material is now in
`Lean.Elab.MutualInductive`, and each command plugs into this mutual
inductive elaboration framework with the logic specific to the
respective command. For example, `structure` has code to add projections
after the inductive types are added to the environment.

Closes #4182
2024-11-22 09:20:07 +00:00

104 lines
2.7 KiB
Text
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/-!
# Tests of universe constraint testing in the `inductive` command
-/
set_option pp.mvars false
set_option pp.universes true
/-!
Given the resultant type, infer that the `x` parameter is `Type`.
-/
inductive T0 : Type where
| mk (x : PUnit.{_+1})
/-- info: T0.mk (x : PUnit.{1}) : T0 -/
#guard_msgs in #check T0.mk
/-!
Given the resultant type, infer that the `x` parameter is `Type` as well.
-/
inductive T1 : Type where
| mk (x : PUnit.{_+1} × PUnit.{_+1})
/-- info: T1.mk (x : Prod.{0, 0} PUnit.{1} PUnit.{1}) : T1 -/
#guard_msgs in #check T1.mk
/-!
Given the resultant type is `Prop`, do not do this inference. Get two universe levels.
-/
inductive T3 : Prop where
| mk (x : PUnit.{_+1} × PUnit.{_+1})
/-- info: T3.mk.{u_1, u_2} (x : Prod.{u_1, u_2} PUnit.{u_1 + 1} PUnit.{u_2 + 1}) : T3.{u_1, u_2} -/
#guard_msgs in #check T3.mk
/-!
Given the resultant type, fail to infer a level for `PUnit` if there's not a unique solution.
-/
/--
error: invalid universe level in constructor 'E0.mk', parameter 'x' has type
PUnit.{u_1}
at universe level
u_1
which is not less than or equal to the inductive type's resulting universe level
1
-/
#guard_msgs in
inductive E0 : Type where
| mk (x : PUnit)
/-!
Given the resultant type, fail to infer a level for `PUnit` if there's not a unique solution.
-/
/--
error: invalid universe level in constructor 'E1.mk', parameter 'x' has type
Prod.{u_1, u_2} PUnit.{u_1 + 1} PUnit.{u_2 + 1}
at universe level
max (u_1+1) (u_2+1)
which is not less than or equal to the inductive type's resulting universe level
2
-/
#guard_msgs in
inductive E1 : Type 1 where
| mk (x : PUnit × PUnit)
/-!
`Sort` polymorphism is not allowed.
-/
/--
error: invalid universe polymorphic resulting type, the resulting universe is not 'Prop', but it may be 'Prop' for some parameter values:
Sort u
Possible solution: use levels of the form 'max 1 _' or '_ + 1' to ensure the universe is of the form 'Type _'.
-/
#guard_msgs in
inductive P (α : Sort u) : Sort u where
| mk (x : α)
/-!
Errors for `structure` are specialized to talking about fields.
-/
/--
error: invalid universe level for field 'α', has type
Type
at universe level
2
which is not less than or equal to the structure's resulting universe level
1
-/
#guard_msgs in
structure A : Type where
α : Type
/-!
Errors for `structure` talk about parent projection fields too.
(Note: it could easily point to `A'` and say the error is field `α`.)
-/
structure A' where
α : Type
/--
error: invalid universe level for field 'toA'', has type
A'
at universe level
2
which is not less than or equal to the structure's resulting universe level
1
-/
#guard_msgs in
structure B extends A' : Type