fix: improve error message when projecting from zero-field type (#9386)
This PR improves a confusing error message that occurred when attempting to project from a zero-field structure. Closes #9312
This commit is contained in:
parent
e9a318df16
commit
3b58a7d36b
2 changed files with 34 additions and 0 deletions
|
|
@ -1301,6 +1301,9 @@ private def resolveLValAux (e : Expr) (eType : Expr) (lval : LVal) : TermElabM L
|
|||
So, we don't projection functions for it. Thus, we use `Expr.proj` -/
|
||||
return LValResolution.projIdx structName (idx - 1)
|
||||
else
|
||||
if numFields == 0 then
|
||||
throwLValError e eType m!"Invalid projection: Projections are not supported on this type \
|
||||
because it has no fields"
|
||||
let (fields, bounds) := if numFields == 1 then
|
||||
(m!"field", m!"the only valid index is 1")
|
||||
else
|
||||
|
|
|
|||
31
tests/lean/run/9312.lean
Normal file
31
tests/lean/run/9312.lean
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
/-!
|
||||
# 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 are not supported on this type because it has no fields
|
||||
{ }
|
||||
has type
|
||||
MyEmpty
|
||||
-/
|
||||
#guard_msgs in
|
||||
#check (MyEmpty.mk).1
|
||||
|
||||
inductive T where
|
||||
| a
|
||||
|
||||
/--
|
||||
error: Invalid projection: Projections are not supported on this type because it has no fields
|
||||
T.a
|
||||
has type
|
||||
T
|
||||
-/
|
||||
#guard_msgs in
|
||||
#check (T.a).1
|
||||
Loading…
Add table
Reference in a new issue