mirror of
https://github.com/nim-lang/Nim.git
synced 2026-04-19 22:10:33 +00:00
fix jsonutils with generic sandwiches, don't use strformat (#24560)
fixes #24559 The strformat macros have the problem that they don't capture symbols, so don't use them in the generic `fromJson` proc here. Also `fromJson` refers to `jsonTo` before it is declared which doesn't capture it, so it's now forward declared.
This commit is contained in:
11
tests/stdlib/mjsonutilssandwich.nim
Normal file
11
tests/stdlib/mjsonutilssandwich.nim
Normal file
@@ -0,0 +1,11 @@
|
||||
import std/[json, jsonutils]
|
||||
|
||||
type
|
||||
Kind* = enum kind1
|
||||
Foo* = ref object
|
||||
bleh: string
|
||||
case kind*: Kind # Remove these lines and everything works 🤡
|
||||
of kind1: discard # Remove these lines and everything works 🤡
|
||||
|
||||
proc unserialize*[T](s: string) =
|
||||
discard jsonTo(parseJson(s), T)
|
||||
10
tests/stdlib/tjsonutilssandwich.nim
Normal file
10
tests/stdlib/tjsonutilssandwich.nim
Normal file
@@ -0,0 +1,10 @@
|
||||
discard """
|
||||
action: compile
|
||||
"""
|
||||
|
||||
# issue #24559
|
||||
|
||||
import mjsonutilssandwich
|
||||
# import std/[json, jsonutils] # Add this line and everything works 🤡
|
||||
|
||||
unserialize[Foo]("{}")
|
||||
Reference in New Issue
Block a user