fix: add_decl_doc should check that declarations are local (#3311)

This was causing a panic previously, [reported on
Zulip](https://leanprover.zulipchat.com/#narrow/stream/287929-mathlib4/topic/CI.20errors.20that.20are.20not.20local.20errors/near/420986393).
This commit is contained in:
Mario Carneiro 2024-02-12 04:04:51 -08:00 committed by GitHub
parent 1965a022eb
commit fbedb79b46
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 6 additions and 0 deletions

View file

@ -722,6 +722,8 @@ opaque elabEval : CommandElab
match stx with
| `($doc:docComment add_decl_doc $id) =>
let declName ← resolveGlobalConstNoOverloadWithInfo id
unless ((← getEnv).getModuleIdxFor? declName).isNone do
throwError "invalid 'add_decl_doc', declaration is in an imported module"
if let .none ← findDeclarationRangesCore? declName then
-- this is only relevant for declarations added without a declaration range
-- in particular `Quot.mk` et al which are added by `init_quot`

View file

@ -102,3 +102,6 @@ def printRangesTest : MetaM Unit := do
printRanges `g.foo
#eval printRangesTest
/-- no dice -/
add_decl_doc Nat.add

View file

@ -189,3 +189,4 @@ g.foo :=
charUtf16 := 44,
endPos := { line := 42, column := 47 },
endCharUtf16 := 47 } }
docStr.lean:106:0-107:20: error: invalid 'add_decl_doc', declaration is in an imported module