Tighten the conversion from tyRange to scalar types (#10495)
* Tighten the conversion from tyRange to scalar types. Introduce the `isIntConv` rule for unsigned types. Do not allow mixed-signedness conversions between ranges and scalar types. * More json adjustments
This commit is contained in:
parent
c5dbb0379f
commit
71df1b060b
3 changed files with 66 additions and 14 deletions
|
|
@ -313,6 +313,24 @@ proc `%`*(s: string): JsonNode =
|
|||
result.kind = JString
|
||||
result.str = s
|
||||
|
||||
proc `%`*(n: uint): JsonNode =
|
||||
## Generic constructor for JSON data. Creates a new `JInt JsonNode`.
|
||||
new(result)
|
||||
result.kind = JInt
|
||||
result.num = BiggestInt(n)
|
||||
|
||||
proc `%`*(n: int): JsonNode =
|
||||
## Generic constructor for JSON data. Creates a new `JInt JsonNode`.
|
||||
new(result)
|
||||
result.kind = JInt
|
||||
result.num = n
|
||||
|
||||
proc `%`*(n: BiggestUInt): JsonNode =
|
||||
## Generic constructor for JSON data. Creates a new `JInt JsonNode`.
|
||||
new(result)
|
||||
result.kind = JInt
|
||||
result.num = BiggestInt(n)
|
||||
|
||||
proc `%`*(n: BiggestInt): JsonNode =
|
||||
## Generic constructor for JSON data. Creates a new `JInt JsonNode`.
|
||||
new(result)
|
||||
|
|
@ -1757,17 +1775,37 @@ when isMainModule:
|
|||
# Generate constructors for range[T] types
|
||||
block:
|
||||
type
|
||||
Q1 = range[0..10]
|
||||
Q2 = range[0'i8..10'i8]
|
||||
Q3 = range[0'u16..10'u16]
|
||||
Q1 = range[0'u8 .. 50'u8]
|
||||
Q2 = range[0'u16 .. 50'u16]
|
||||
Q3 = range[0'u32 .. 50'u32]
|
||||
Q4 = range[0'i8 .. 50'i8]
|
||||
Q5 = range[0'i16 .. 50'i16]
|
||||
Q6 = range[0'i32 .. 50'i32]
|
||||
Q7 = range[0'f32 .. 50'f32]
|
||||
Q8 = range[0'f64 .. 50'f64]
|
||||
Q9 = range[0 .. 50]
|
||||
|
||||
X = object
|
||||
m1: Q1
|
||||
m2: Q2
|
||||
m3: Q3
|
||||
m4: Q4
|
||||
m5: Q5
|
||||
m6: Q6
|
||||
m7: Q7
|
||||
m8: Q8
|
||||
m9: Q9
|
||||
|
||||
let
|
||||
obj = X(m1: 1, m2: 2'i8, m3: 3'u16)
|
||||
jsonObj = %obj
|
||||
desObj = to(jsonObj, type(obj))
|
||||
let obj = X(
|
||||
m1: Q1(42),
|
||||
m2: Q2(42),
|
||||
m3: Q3(42),
|
||||
m4: Q4(42),
|
||||
m5: Q5(42),
|
||||
m6: Q6(42),
|
||||
m7: Q7(42),
|
||||
m8: Q8(42),
|
||||
m9: Q9(42)
|
||||
)
|
||||
|
||||
doAssert(desObj == obj)
|
||||
doAssert(obj == to(%obj, type(obj)))
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue