fix: fixes #679
This commit is contained in:
parent
fc1ec438b8
commit
fe7b750bce
3 changed files with 15 additions and 3 deletions
|
|
@ -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
8
tests/lean/679.lean
Normal 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
|
||||
1
tests/lean/679.lean.expected.out
Normal file
1
tests/lean/679.lean.expected.out
Normal file
|
|
@ -0,0 +1 @@
|
|||
Except.ok Lean.Name.anonymous
|
||||
Loading…
Add table
Reference in a new issue