lean4-htt/tests/elab/9312.lean
Kyle Miller d8accf47b3
chore: use terminology "non-recursive structure" instead of "struct-like" (#12749)
This PR changes "structure-like" terminology to "non-recursive
structure" across internal documentation, error messages, the
metaprogramming API, and the kernel, to clarify Lean's type theory. A
*structure* is a one-constructor inductive type with no indices — these
can be created by either the `structure` or `inductive` commands — and
are supported by the primitive `Expr.proj` projections. Only
*non-recursive* structures have an eta conversion rule. The PR
description contains the APIs that were renamed.

Addresses RFC #5891, which proposed this rename. The change is motivated
by the need to distinguish between `structure`-defined structures,
structures, and non-recursive structures. Especially since #5783, which
enabled the `structure` command to define recursive structures,
"structure-like" has been easy to misunderstand.

Changes:
- Kernel: `is_structure_like()` -> `is_non_rec_structure()`
- `Lean.isStructureLike` -> `Lean.isNonRecStructure`
- `Lean.matchConstStructLike` -> `Lean.matchConstNonRecStructure`
- `Lean.getStructureLikeCtor?` -> `Lean.getNonRecStructureCtor?`
- `Lean.getStructureLikeNumFields` -> `Lean.getNonRecStructureNumFields`
- `Lean.Expr.proj`: extended and corrected documentation (note: despite
the fact that not every projection can be written as a recursor
application, I left in this claim since it seems good to document a
more-restrictive specification, and some users have requested the kernel
be more restrictive in this way)

Closes #5891
2026-03-09 03:44:38 +00:00

29 lines
660 B
Text

/-!
# Projections on types without fields
https://github.com/leanprover/lean4/issues/9312
Ensures that a suitable error message is displayed when attempting to project from a type that has
no fields.
-/
structure MyEmpty where
/--
error: Invalid projection: Projections extract constructor fields for one-constructor inductive types. The expression
{ }
has type `MyEmpty` which has no fields.
-/
#guard_msgs in
#check (MyEmpty.mk).1
inductive T where
| a
/--
error: Invalid projection: Projections extract constructor fields for one-constructor inductive types. The expression
T.a
has type `T` which has no fields.
-/
#guard_msgs in
#check (T.a).1