lean4-htt/tests/lean/run/ppRoundtripDefs.lean
Sebastian Ullrich 2833c61a60 fix: respect preresolved names at resolveConst*
This makes sure we can properly quote e.g. `deriving` clauses and avoids
a suspicious `eraseMacroScopes` call (though not at `Elab.Syntax`, since
categories do not have to be declaration names)
2021-07-30 07:17:50 -07:00

26 lines
902 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
open Lean Lean.Meta Lean.Elab Lean.Elab.Term Lean.Elab.Command Lean.PrettyPrinter
syntax (name := roundtrip) "#roundtrip " ident : command
@[commandElab roundtrip] def elabRoundtrip : CommandElab
| `(#roundtrip%$tk $name:ident) => withoutModifyingEnv do
let [name] ← resolveGlobalConst name | throwError "cannot resolve name"
let some cInfo ← (← getEnv).find? name | throwError "no such decl: {name}"
let ns := cInfo.name.getRoot
let cmdStx ← liftTermElabM none do
let typeStx ← delab ns [] cInfo.type {}
let valueStx ← delab ns [] cInfo.value! {}
`(noncomputable def $(mkIdent (ns ++ `foo)):declId : $typeStx:term := $valueStx:term)
elabCommand cmdStx
| _ => throwUnsupportedSyntax
#roundtrip Nat.add
#roundtrip Std.Range.forIn.loop
def hasMonadInst {α : Type u} {m : Type u → Type v} [Monad m] (x : m α) : m α := x
#roundtrip hasMonadInst