Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

without statement can fail in generic code #11

Closed
markspanbroek opened this issue Jun 8, 2022 · 0 comments · Fixed by #13
Closed

without statement can fail in generic code #11

markspanbroek opened this issue Jun 8, 2022 · 0 comments · Fixed by #13

Comments

@markspanbroek
Copy link
Member

Context

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.

https://github.com/status-im/questionable/blob/d7e9f0bf7fec14df13a26e699437a2fe577b26ba/questionable/withoutresult.nim#L37

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants