Use the without statement
on an expression that returns Result
whereby you access the error
inside generic code.
Failure
The error is set to nil, whereas it should have a value
Reproduce
test "without statement works in generic code":
proc test(_: type) =
without a =? int.failure "error", e:
check e.msg == "error"
return
fail
test(int)
Removing the generic parameter makes the test pass.
Possible cause
Replacing infix operator =? with override=? override doesn't seem to work. It seems that the =? has already been evaluated by the compiler before it evaluates the without template.
Context
Use the
without
statement on an expression that returnsResult
whereby you access the error inside generic code.Failure
The error is set to nil, whereas it should have a value
Reproduce
Removing the generic parameter makes the test pass.
Possible cause
Replacing infix operator
=?
withoverride=?
override doesn't seem to work. It seems that the=?
has already been evaluated by the compiler before it evaluates thewithout
template.https://github.com/status-im/questionable/blob/d7e9f0bf7fec14df13a26e699437a2fe577b26ba/questionable/withoutresult.nim#L37