fix: coinductive syntax causing panic in macro scopes (#13420)

This PR fixes a panic when `coinductive` predicates are defined inside
macro scopes where constructor names carry macro scopes. The existing
guard only checked the declaration name for macro scopes, missing the
case where constructor identifiers are generated inside a macro
quotation and thus carry macro scopes. This caused
`removeFunctorPostfixInCtor` to panic on `Name.num` components from
macro scope encoding.

Closes #13415
This commit is contained in:
Wojciech Różowski 2026-04-15 19:50:31 +01:00 committed by GitHub
parent 9b1426fd9c
commit fe77e4d2d1
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 15 additions and 0 deletions

View file

@ -73,6 +73,8 @@ private def inductiveSyntaxToView (modifiers : Modifiers) (decl : Syntax) (isCoi
throwError "Constructor cannot be `protected` because it is in a `private` inductive datatype"
checkValidCtorModifier ctorModifiers
let ctorName := ctor.getIdAt 3
if ctorName.hasMacroScopes && isCoinductive then
throwError "Coinductive predicates are not allowed inside of macro scopes"
let ctorName := declName ++ ctorName
let ctorName ← withRef ctor[3] <| applyVisibility ctorModifiers ctorName
let (binders, type?) := expandOptDeclSig ctor[4]

13
tests/elab/13415.lean Normal file
View file

@ -0,0 +1,13 @@
macro "co " x:ident : command => do
`(coinductive $x : Prop where | ok)
/-- error: Coinductive predicates are not allowed inside of macro scopes -/
#guard_msgs in
co f
macro "co2" : command => do
`(coinductive test : Prop where | ctor)
/-- error: Coinductive predicates are not allowed inside of macro scopes -/
#guard_msgs in
co2