Reduce warnings in Nim 1.0.2; Fix #16
This commit is contained in:
parent
448a03ed4b
commit
ae60eef4e8
|
@ -76,7 +76,6 @@ macro enumAllSerializedFieldsImpl(T: type, body: untyped): untyped =
|
||||||
var typeImpl: NimNode
|
var typeImpl: NimNode
|
||||||
let isSymbol = not typeAst.isTuple
|
let isSymbol = not typeAst.isTuple
|
||||||
|
|
||||||
|
|
||||||
if not isSymbol:
|
if not isSymbol:
|
||||||
typeImpl = typeAst
|
typeImpl = typeAst
|
||||||
else:
|
else:
|
||||||
|
@ -100,10 +99,10 @@ macro enumAllSerializedFieldsImpl(T: type, body: untyped): untyped =
|
||||||
let fieldNameVarTemplate =
|
let fieldNameVarTemplate =
|
||||||
if isSymbol:
|
if isSymbol:
|
||||||
quote:
|
quote:
|
||||||
template `fieldNameVar`: auto = `fieldName`
|
template `fieldNameVar`: auto {.used.} = `fieldName`
|
||||||
else:
|
else:
|
||||||
quote:
|
quote:
|
||||||
template `fieldNameVar`: auto = $`fieldIndex`
|
template `fieldNameVar`: auto {.used.} = $`fieldIndex`
|
||||||
# we can't access .Fieldn, so our helper knows
|
# we can't access .Fieldn, so our helper knows
|
||||||
# to parseInt this
|
# to parseInt this
|
||||||
|
|
||||||
|
@ -116,12 +115,12 @@ macro enumAllSerializedFieldsImpl(T: type, body: untyped): untyped =
|
||||||
result.add quote do:
|
result.add quote do:
|
||||||
block:
|
block:
|
||||||
`fieldNameVarTemplate`
|
`fieldNameVarTemplate`
|
||||||
template fieldCaseDiscriminator: auto = `discriminator`
|
template fieldCaseDiscriminator: auto {.used.} = `discriminator`
|
||||||
template fieldCaseBranches: auto = `branches`
|
template fieldCaseBranches: auto {.used.} = `branches`
|
||||||
|
|
||||||
# type `fieldTypeVar` = `fieldType`
|
# type `fieldTypeVar` = `fieldType`
|
||||||
# TODO: This is a work-around for a classic Nim issue:
|
# TODO: This is a work-around for a classic Nim issue:
|
||||||
type `FieldTypeSym` = type(`field`)
|
type `FieldTypeSym` {.used.} = type(`field`)
|
||||||
`body`
|
`body`
|
||||||
|
|
||||||
i += 1
|
i += 1
|
||||||
|
@ -180,7 +179,7 @@ proc makeFieldReadersTable(RecordType, Reader: distinct type):
|
||||||
enumAllSerializedFields(RecordType):
|
enumAllSerializedFields(RecordType):
|
||||||
proc readField(obj: var RecordType, reader: var Reader) {.gcsafe, nimcall.} =
|
proc readField(obj: var RecordType, reader: var Reader) {.gcsafe, nimcall.} =
|
||||||
when RecordType is tuple:
|
when RecordType is tuple:
|
||||||
const i = fieldName.parseInt
|
const i = fieldName.parseInt
|
||||||
try:
|
try:
|
||||||
|
|
||||||
type F = FieldTag[RecordType, fieldName, type(FieldType)]
|
type F = FieldTag[RecordType, fieldName, type(FieldType)]
|
||||||
|
@ -270,11 +269,11 @@ macro setSerializedFields*(T: typedesc, fields: varargs[untyped]): untyped =
|
||||||
fieldTypeVar, typ, field,
|
fieldTypeVar, typ, field,
|
||||||
body) =
|
body) =
|
||||||
block:
|
block:
|
||||||
const fieldNameVar = fieldName
|
const fieldNameVar {.used.} = fieldName
|
||||||
type fieldTypeVar = type(default(typ).field)
|
type fieldTypeVar {.used.} = type(default(typ).field)
|
||||||
|
|
||||||
template fieldCaseDiscriminator: auto = ""
|
template fieldCaseDiscriminator: auto {.used.} = ""
|
||||||
template fieldCaseBranches: auto = nil
|
template fieldCaseBranches: auto {.used.} = nil
|
||||||
|
|
||||||
body
|
body
|
||||||
|
|
||||||
|
|
|
@ -67,7 +67,7 @@ type
|
||||||
data*: seq[int]
|
data*: seq[int]
|
||||||
|
|
||||||
AnonTuple* = (int, string, float64)
|
AnonTuple* = (int, string, float64)
|
||||||
|
|
||||||
AbcTuple* = tuple[a: int, b: string, c: float64]
|
AbcTuple* = tuple[a: int, b: string, c: float64]
|
||||||
XyzTuple* = tuple[x: int, y: string, z: float64]
|
XyzTuple* = tuple[x: int, y: string, z: float64]
|
||||||
|
|
||||||
|
@ -127,6 +127,10 @@ template roundtripChecks*(Format: type, value: auto, expectedResult: auto) =
|
||||||
except SerializationError as err:
|
except SerializationError as err:
|
||||||
checkpoint "(serialization error): " & err.formatMsg("(encoded value)")
|
checkpoint "(serialization error): " & err.formatMsg("(encoded value)")
|
||||||
fail()
|
fail()
|
||||||
|
except:
|
||||||
|
when compiles($value):
|
||||||
|
checkpoint "unexpected failure in roundtrip test for " & $value
|
||||||
|
raise
|
||||||
|
|
||||||
template roundtripTest*(Format: type, value: auto, expectedResult: auto) =
|
template roundtripTest*(Format: type, value: auto, expectedResult: auto) =
|
||||||
mixin `==`
|
mixin `==`
|
||||||
|
@ -141,12 +145,6 @@ template roundtripChecks*(Format: type, value: auto) =
|
||||||
roundtripChecks(Format, value, NoExpectedResult(0))
|
roundtripChecks(Format, value, NoExpectedResult(0))
|
||||||
|
|
||||||
proc executeRoundtripTests*(Format: type) =
|
proc executeRoundtripTests*(Format: type) =
|
||||||
mixin init, ReaderType, WriterType
|
|
||||||
|
|
||||||
type
|
|
||||||
Reader = ReaderType Format
|
|
||||||
Writer = WriterType Format
|
|
||||||
|
|
||||||
template roundtrip(val: untyped) =
|
template roundtrip(val: untyped) =
|
||||||
mixin supports
|
mixin supports
|
||||||
# TODO:
|
# TODO:
|
||||||
|
@ -160,18 +158,20 @@ proc executeRoundtripTests*(Format: type) =
|
||||||
template intTests(T: untyped) =
|
template intTests(T: untyped) =
|
||||||
roundtrip low(T)
|
roundtrip low(T)
|
||||||
roundtrip high(T)
|
roundtrip high(T)
|
||||||
for i in 0..1000:
|
when false:
|
||||||
roundtrip rand(low(T)..high(T))
|
# TODO:
|
||||||
|
# rand(low..high) produces an overflow error in Nim 1.0.2
|
||||||
|
for i in 0..1000:
|
||||||
|
roundtrip rand(low(T)..(high(T) div 2))
|
||||||
|
|
||||||
when false:
|
intTests int8
|
||||||
intTests int8
|
intTests int16
|
||||||
intTests int16
|
intTests int32
|
||||||
intTests int32
|
intTests int64
|
||||||
intTests int64
|
intTests uint8
|
||||||
intTests uint8
|
intTests uint16
|
||||||
intTests uint16
|
intTests uint32
|
||||||
intTests uint32
|
intTests uint64
|
||||||
intTests uint64
|
|
||||||
|
|
||||||
roundtrip ""
|
roundtrip ""
|
||||||
roundtrip "a"
|
roundtrip "a"
|
||||||
|
@ -257,8 +257,8 @@ proc executeRoundtripTests*(Format: type) =
|
||||||
roundtrip t3
|
roundtrip t3
|
||||||
|
|
||||||
test "sets":
|
test "sets":
|
||||||
var s1 = toSet([1, 2, 3, 1, 4, 2])
|
var s1 = toHashSet([1, 2, 3, 1, 4, 2])
|
||||||
var s2 = HoldsSet(a: 100, s: toSet(["a", "b", "c"]))
|
var s2 = HoldsSet(a: 100, s: toHashSet(["a", "b", "c"]))
|
||||||
|
|
||||||
roundtrip s1
|
roundtrip s1
|
||||||
roundtrip s2
|
roundtrip s2
|
||||||
|
@ -274,7 +274,6 @@ proc executeReaderWriterTests*(Format: type) =
|
||||||
|
|
||||||
type
|
type
|
||||||
Reader = ReaderType Format
|
Reader = ReaderType Format
|
||||||
Writer = WriterType Format
|
|
||||||
|
|
||||||
suite(typetraits.name(Format) & " read/write tests"):
|
suite(typetraits.name(Format) & " read/write tests"):
|
||||||
test "Low-level field reader test":
|
test "Low-level field reader test":
|
||||||
|
|
Loading…
Reference in New Issue