add `{.raises.}` annotation to `writeValue` (#62)
Tag `writeValue` overrides with `{.raises: [IOError].}`.
This commit is contained in:
parent
384eb2561e
commit
4bdbc29e54
|
@ -104,7 +104,8 @@ template saveFile*(Format: type, filename: string, value: auto, params: varargs[
|
||||||
template borrowSerialization*(Alias: type) {.dirty.} =
|
template borrowSerialization*(Alias: type) {.dirty.} =
|
||||||
bind distinctBase
|
bind distinctBase
|
||||||
|
|
||||||
proc writeValue*[Writer](writer: var Writer, value: Alias) =
|
proc writeValue*[Writer](
|
||||||
|
writer: var Writer, value: Alias) {.raises: [IOError].} =
|
||||||
mixin writeValue
|
mixin writeValue
|
||||||
writeValue(writer, distinctBase value)
|
writeValue(writer, distinctBase value)
|
||||||
|
|
||||||
|
@ -115,7 +116,8 @@ template borrowSerialization*(Alias: type) {.dirty.} =
|
||||||
template borrowSerialization*(Alias: distinct type,
|
template borrowSerialization*(Alias: distinct type,
|
||||||
OriginalType: distinct type) {.dirty.} =
|
OriginalType: distinct type) {.dirty.} =
|
||||||
|
|
||||||
proc writeValue*[Writer](writer: var Writer, value: Alias) =
|
proc writeValue*[Writer](
|
||||||
|
writer: var Writer, value: Alias) {.raises: [IOError].} =
|
||||||
mixin writeValue
|
mixin writeValue
|
||||||
writeValue(writer, OriginalType value)
|
writeValue(writer, OriginalType value)
|
||||||
|
|
||||||
|
@ -161,4 +163,3 @@ template writeValue*(stream: OutputStream,
|
||||||
type WriterType = Writer(Format)
|
type WriterType = Writer(Format)
|
||||||
var writer = unpackArgs(init, [WriterType, stream, params])
|
var writer = unpackArgs(init, [WriterType, stream, params])
|
||||||
writeValue writer, value
|
writeValue writer, value
|
||||||
|
|
||||||
|
|
|
@ -408,7 +408,7 @@ proc genCustomSerializationForType(Format, typ: NimNode,
|
||||||
result.add quote do:
|
result.add quote do:
|
||||||
type WriterType = Writer(`Format`)
|
type WriterType = Writer(`Format`)
|
||||||
proc writeValue*(`writerSym`: var WriterType, `valueSym`: `typ`)
|
proc writeValue*(`writerSym`: var WriterType, `valueSym`: `typ`)
|
||||||
{.raises: [IOError, Defect], gcsafe.} =
|
{.raises: [IOError], gcsafe.} =
|
||||||
`writeBody`
|
`writeBody`
|
||||||
|
|
||||||
macro useCustomSerialization*(Format: typed, field: untyped, body: untyped): untyped =
|
macro useCustomSerialization*(Format: typed, field: untyped, body: untyped): untyped =
|
||||||
|
|
|
@ -113,16 +113,16 @@ Simple.setSerializedFields distance, x, y
|
||||||
|
|
||||||
proc default(T: typedesc): T = discard
|
proc default(T: typedesc): T = discard
|
||||||
|
|
||||||
func caseObjectEquals(a, b: CaseObject): bool
|
func caseObjectEquals(a, b: CaseObject): bool {.raises: [].}
|
||||||
|
|
||||||
func `==`*(a, b: CaseObjectRef): bool =
|
func `==`*(a, b: CaseObjectRef): bool {.raises: [].} =
|
||||||
let nils = ord(a.isNil) + ord(b.isNil)
|
let nils = ord(a.isNil) + ord(b.isNil)
|
||||||
if nils == 0:
|
if nils == 0:
|
||||||
caseObjectEquals(a[], b[])
|
caseObjectEquals(a[], b[])
|
||||||
else:
|
else:
|
||||||
nils == 2
|
nils == 2
|
||||||
|
|
||||||
func caseObjectEquals(a, b: CaseObject): bool =
|
func caseObjectEquals(a, b: CaseObject): bool {.raises: [].} =
|
||||||
# TODO This is needed to work-around a Nim overload selection issue
|
# TODO This is needed to work-around a Nim overload selection issue
|
||||||
if a.kind != b.kind: return false
|
if a.kind != b.kind: return false
|
||||||
|
|
||||||
|
@ -369,4 +369,3 @@ proc executeReaderWriterTests*(Format: type) =
|
||||||
findFieldReader(bazFields[], "some_other_name", pos) == nil
|
findFieldReader(bazFields[], "some_other_name", pos) == nil
|
||||||
|
|
||||||
executeRoundtripTests(Format)
|
executeRoundtripTests(Format)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue