lean4 icon indicating copy to clipboard operation
lean4 copied to clipboard

doc: improve error message for unknown attributes

Open 0rca opened this issue 5 months ago • 2 comments

This PR improves error message for unknown attributes, including labels. Instead of "unknown attribute", the message how instructs the user to define/import their attributes/labels in/from a separate file.

Closes #4011


ScreenFloat Shot of Ghostty on 2026-06-29 at 14-11-08

0rca avatar Jun 29 '26 06:06 0rca

Mathlib CI status (docs):

  • ❗ Batteries/Mathlib CI will not be attempted unless your PR branches off the nightly-with-mathlib branch. Try git rebase de5b7f235a71d301bffbb2dbe607ec36dd58cce7 --onto 84b251f7390c20a0a00a221050ab4a6e6c46a191. You can force Mathlib CI using the force-mathlib-ci label. (2026-06-29 06:44:33)
  • ✅ Mathlib branch lean-pr-testing-14213 has successfully built against this PR. (2026-07-05 09:40:30) View Log
  • ✅ Mathlib branch lean-pr-testing-14213 has successfully built against this PR. (2026-07-13 06:58:12) View Log
  • ❗ Mathlib CI can not be attempted yet, as the nightly-testing-2026-07-18 tag does not exist there yet. We will retry when you push more commits. If you rebase your branch onto nightly-with-mathlib, Mathlib CI should run now. You can force Mathlib CI using the force-mathlib-ci label. (2026-07-18 12:06:14)

Reference manual CI status:

  • ❗ Reference manual CI will not be attempted unless your PR branches off the nightly-with-manual branch. Try git rebase de5b7f235a71d301bffbb2dbe607ec36dd58cce7 --onto 84b251f7390c20a0a00a221050ab4a6e6c46a191. You can force reference manual CI using the force-manual-ci label. (2026-06-29 06:44:35)
  • ✅ Reference manual branch lean-pr-testing-14213 has successfully built against this PR. (2026-07-05 08:45:24) View Log
  • 🟡 Reference manual branch lean-pr-testing-14213 build against this PR didn't complete normally. (2026-07-05 08:46:32) View Log
  • ✅ Reference manual branch lean-pr-testing-14213 has successfully built against this PR. (2026-07-13 06:04:30) View Log
  • 🟡 Reference manual branch lean-pr-testing-14213 build against this PR didn't complete normally. (2026-07-13 06:06:25) View Log
  • ✅ Reference manual branch lean-pr-testing-14213 has successfully built against this PR. (2026-07-18 12:11:19) View Log
  • 🟡 Reference manual branch lean-pr-testing-14213 build against this PR didn't complete normally. (2026-07-18 12:12:33) View Log

leanprover-bot avatar Jun 29 '26 06:06 leanprover-bot

That would be best, indeed. However, my understanding of Lean internals is sketchy at best.

According to it, I would need to:

  1. extend Lean.Parser.Command.«initialize» to be able to tell if the command is initializing an attribute (or LabelAttribute, specifically)
  2. introduce a new extension similar to builtin_initialize declRangeExt : MapDeclarationExtension DeclarationRanges, but non-persistent
  3. write to it from the initialize similarly to how addDeclarationRangesForBuiltin does today.
  4. consult this extension in elabAttr to see it initialize has already seen it.

Is this what you had in mind? Please, let me know if you think this is something I could work on, or if this is too complicated for a first-time contributor.


By the way, there's another, simpler way, but it is specific to LabelAttribute, and feels like a hack, tbh. We can inspect the syntax of the attribute in elabAttr. Because LabelAttribute declares its own named syntax, we can tell if the attribute has or has not been declared, look:

ScreenFloat Shot of Ghostty on 2026-07-13 at 13-15-14 ScreenFloat Shot of Ghostty on 2026-07-13 at 13-17-40

I've updated the PR with this PoC.

0rca avatar Jul 13 '26 05:07 0rca