lean4-htt/tests/lean/run/univ_out_params.lean
Leonardo de Moura 483cad5fd6
feat: add [univ_out_params] (#12423)
This PR adds the attribute `@[univ_out_params]` for specifying which
universe levels should be treated as output parameters. By default, any
universe level that does not occur in any input parameter is considered
an output parameter.
2026-02-11 15:42:00 +00:00

39 lines
1 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.

import Lean
open Lean Meta
@[univ_out_params v]
class ToLvl₁.{u, v} : Type where
dummy : ∀ (_ : Sort u) (_ : Sort v), True := fun _ _ => trivial
/-- info: (some #[1]) -/
#guard_msgs in
run_meta do IO.println <| getOutLevelParamPositions? (← getEnv) ``ToLvl₁
@[univ_out_params]
class ToLvl₂.{u, v} : Type where
dummy : ∀ (_ : Sort u) (_ : Sort v), True := fun _ _ => trivial
/-- info: (some #[]) -/
#guard_msgs in
run_meta do IO.println <| getOutLevelParamPositions? (← getEnv) ``ToLvl₂
@[univ_out_params v u]
class ToLvl₃.{u, v} : Type where
dummy : ∀ (_ : Sort u) (_ : Sort v), True := fun _ _ => trivial
/-- info: (some #[0, 1]) -/
#guard_msgs in
run_meta do IO.println <| getOutLevelParamPositions? (← getEnv) ``ToLvl₃
/-- error: `v` is not a universe parameter of `Foo` -/
#guard_msgs in
@[univ_out_params v]
class Foo (α : Type u) where
a : α
/-- error: invalid `univ_out_params`, `Bla` is not a class -/
#guard_msgs in
@[univ_out_params u]
structure Bla (α : Type u) where
a : α