replace defer by try/finally to avoid 0.19.6 compiler bug (#15)

This commit is contained in:
Mamy Ratsimbazafy 2019-09-11 14:09:58 -04:00 committed by GitHub
parent 80da30b031
commit 448a03ed4b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 11 additions and 11 deletions

View File

@ -89,21 +89,21 @@ template loadFile*(Format: distinct type,
params: varargs[untyped]): auto =
mixin init, ReaderType
var stream = openFile(filename)
defer:
try:
# TODO:
# Remove this when statement once the following bug is fixed:
# https://github.com/nim-lang/Nim/issues/9996
when astToStr(params) != "":
var reader = init(ReaderType(Format), stream, params)
else:
var reader = init(ReaderType(Format), stream)
reader.readValue(RecordType)
finally:
# TODO: destructors
if not stream.isNil:
stream[].close()
# TODO:
# Remove this when statement once the following bug is fixed:
# https://github.com/nim-lang/Nim/issues/9996
when astToStr(params) != "":
var reader = init(ReaderType(Format), stream, params)
else:
var reader = init(ReaderType(Format), stream)
reader.readValue(RecordType)
template loadFile*[RecordType](Format: type,
filename: string,
record: var RecordType,