Closed Bulat-Ziganshin closed 1 year ago
I don't know of a way to do this well, unfortunately. Here's an example to illustrate why this is problematic:
proc foo: Result[int, string]
proc bar: Result[int, ref CatchableError]
without a =? foo() and b =? bar(), error:
# what is the type of the `error` variable here?
You could just block and
to allow only the same error type, and still allow without
for basic usage?
You could just block and to allow only the same error type, and still allow without for basic usage?
I think that that would be hard to achieve. The without
macro currently doesn't know anything about the condition that it's evaluating. It doesn't see the and
. It only knows that the condition should evaluate to a boolean. The bindings =?
are implemented as boolean expressions with the side effect of assigning the value of a result to a variable. The and
is just the simple operator on booleans, and doesn't know that it's operating on bindings.
There is also an extensive discussion here - https://github.com/status-im/nim-codex/discussions/41, which should explain the reasoning behind the Result[T, CathableError]
in questionable.
Can it be done?