fix: use Name.appendCore instead of Name.append in unresolveNameGlobal (#3946)
`Name.append` has special handling of macro scopes, and it would cause `unresolveNameGlobal` to panic. Using `Name.appendCore` to append name parts is justified by the fact that it's being used to reassemble a disassembled name. Closes #2291
This commit is contained in:
parent
158979380e
commit
a9db0d2e53
3 changed files with 16 additions and 3 deletions
|
|
@ -4335,8 +4335,13 @@ def addMacroScope (mainModule : Name) (n : Name) (scp : MacroScope) : Name :=
|
|||
Name.mkNum (Name.mkStr (Name.appendCore (Name.mkStr n "_@") mainModule) "_hyg") scp
|
||||
|
||||
/--
|
||||
Append two names that may have macro scopes. The macro scopes in `b` are always erased.
|
||||
If `a` has macro scopes, then they are propagated to the result of `append a b`.
|
||||
Appends two names `a` and `b`, propagating macro scopes from `a` or `b`, if any, to the result.
|
||||
Panics if both `a` and `b` have macro scopes.
|
||||
|
||||
This function is used for the `Append Name` instance.
|
||||
|
||||
See also `Lean.Name.appendCore`, which appends names without any consideration for macro scopes.
|
||||
Also consider `Lean.Name.eraseMacroScopes` to erase macro scopes before appending, if appropriate.
|
||||
-/
|
||||
def Name.append (a b : Name) : Name :=
|
||||
match a.hasMacroScopes, b.hasMacroScopes with
|
||||
|
|
|
|||
|
|
@ -404,7 +404,7 @@ where
|
|||
for _ in [:revComponents.length] do
|
||||
match revComponents with
|
||||
| [] => return none
|
||||
| cmpt::rest => candidate := cmpt ++ candidate; revComponents := rest
|
||||
| cmpt::rest => candidate := Name.appendCore cmpt candidate; revComponents := rest
|
||||
match (← resolveGlobalName candidate) with
|
||||
| [(potentialMatch, _)] => if potentialMatch == n₀ then return some candidate else continue
|
||||
| _ => continue
|
||||
|
|
|
|||
8
tests/lean/run/2291.lean
Normal file
8
tests/lean/run/2291.lean
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
/-!
|
||||
Issue #2291
|
||||
|
||||
The following example would cause the pretty printer to panic.
|
||||
-/
|
||||
|
||||
set_option trace.compiler.simp true in
|
||||
#eval [0]
|
||||
Loading…
Add table
Reference in a new issue