This commit is contained in:
Leonardo de Moura 2021-09-18 15:34:29 -07:00
parent fc1ec438b8
commit fe7b750bce
3 changed files with 15 additions and 3 deletions

View file

@ -69,9 +69,12 @@ instance [ToJson α] [ToJson β] : ToJson (α × β) where
instance : FromJson Name where
fromJson? j := do
let s ← j.getStr?
let some n ← Syntax.decodeNameLit ("`" ++ s)
| throw s!"expected a `Name`, got '{j}'"
return n
if s == "[anonymous]" then
return Name.anonymous
else
let some n ← Syntax.decodeNameLit ("`" ++ s)
| throw s!"expected a `Name`, got '{j}'"
return n
instance : ToJson Name where
toJson n := toString n

8
tests/lean/679.lean Normal file
View file

@ -0,0 +1,8 @@
import Lean
open Lean
def encodeDecode [ToJson α] [FromJson α] (x : α) : Except String α := do
let json ← toJson x
fromJson? json
#eval encodeDecode Name.anonymous

View file

@ -0,0 +1 @@
Except.ok Lean.Name.anonymous