lean4-htt/tests/lean/run/2291.lean
Kyle Miller a1be9ec850
chore: tidying up Lean.unresolveNameGlobal (#4091)
The main loop logic could be simplified, and `if let` could be used to
make control flow more obvious.

Also adds a check for macro scopes to prevent `unresolveNameGlobal` from
returning names with macro scopes in the event there's an alias with
one.

This is a follow up to #3946.
2024-05-10 22:37:34 +00:00

30 lines
740 B
Text
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import Lean.Elab.Command
import Lean.Elab.Open
/-!
Issue #2291
The following example would cause the pretty printer to panic.
-/
set_option trace.compiler.simp true in
#eval [0]
/-!
Fixing the above involved changing `Lean.unresolveNameGlobal`.
Here, we also verify that we do not pretty print using any aliases that have macro scopes.
-/
open Lean in
elab "add_bad_alias " n:ident : command => withFreshMacroScope do
let declName ← Elab.OpenDecl.resolveNameUsingNamespaces [← getCurrNamespace] n
let badName ← MonadQuotation.addMacroScope `bad
modify fun s => { s with env := addAlias s.env badName declName }
def f := 1
add_bad_alias f
-- Formerly was info: bad✝ :
/-- info: f : Nat -/
#guard_msgs in #check (f)