chore: [match_pattern] should enforce [expose] (#9534)

This commit is contained in:
Sebastian Ullrich 2025-07-31 13:51:47 +02:00 committed by GitHub
parent 5e7c4557f8
commit 28f64e57ae
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 7 additions and 3 deletions

View file

@ -31,6 +31,6 @@ both `List.toArray` and `Array.mk`.
-/
-- This function is exported to C, where it is called by `Array.mk`
-- (the constructor) to implement this functionality.
@[inline, match_pattern, pp_nodot, export lean_list_to_array]
@[inline, expose, match_pattern, pp_nodot, export lean_list_to_array]
def List.toArrayImpl (xs : List α) : Array α :=
xs.toArrayAux (Array.mkEmpty xs.length)

View file

@ -19,8 +19,8 @@ namespace Lean.Elab.Tactic.Do.ProofMode
open Lean Elab Meta
open Std.Do Std.Tactic.Do
@[match_pattern] def nameAnnotation := `name
@[match_pattern] def uniqAnnotation := `uniq
@[match_pattern] private def nameAnnotation := `name
@[match_pattern] private def uniqAnnotation := `uniq
structure Hyp where
name : Name

View file

@ -33,6 +33,10 @@ def isYellow (color : String) : Bool :=
@[builtin_doc]
builtin_initialize matchPatternAttr : TagAttribute ←
registerTagAttribute `match_pattern "mark that a definition can be used in a pattern (remark: the dependent pattern matching compiler will unfold the definition)"
(validate := fun declName => do
withExporting (isExporting := !isPrivateName declName) do
if !(← getConstInfo declName).isDefinition then
throwError "invalid `@[match_pattern]` attribute, '{declName}' is not an exposed definition")
@[export lean_has_match_pattern_attribute]
def hasMatchPatternAttribute (env : Environment) (n : Name) : Bool :=