arnetheduck/nim-results

Catch sometimes leads to compile error

Closed this issue · 3 comments

The following code leads to a compile error:

import std/strutils
import pkg/result/../results

let error = 42 # a symbol "error" needs to be in scope to trigger the issue
discard parseInt("foo").catch.error # Error: the field 'v' is not accessible.

The catch template uses the ok and err templates, which in combination with the ambiguity of error in this code, leads to a situation where Nim tries to evaluate the code from the ok template in a scope where v is not visible.

It can be solved by making ok and err procs instead of templates.

cc @zah this is the nim early symbol matching kicking in, right? Is there anything we can do in result (ie detect it and print an informative error at least?)

"fixed" in #26

I have tested nim-lang/Nim#21649 with this issue, it indeed fixes the problem.