import std/tables, sugar
proc getProc(): (proc()) =
var tab: Table[string, string]
capture tab: # Error
return (proc() =
echo "Hello World"
)
(This is the smallest example I could come up with that shows the issue)
If I do that though, I get the following error: "A nested proc can have generic parameters only when it is used as an operand to another routine and the types of the generic paramers can be inferred from the expected signature."
I don't understand what I am doing wrong here, since the nested proc has no parameters at all, not to mention generic ones.
Also, I don't know what is meant by "the types of the generic paramers can be inferred from the expected signature" since I explicitly tell it that it is a Table[string, string].
So my question is, what am I doing wrong here?
In case it helps, this is where the error occurs in my project: https://github.com/Pasu4/animdustry/blob/72b579efc809b5e2244d76fbf6afc550610e4da1/src/jsonapi.nim#L593
If I understand the implementation of capture correctly, this is what your code expands to:
import std/tables, sugar
proc getProc(): (proc()) =
var tab: Table[string, string]
(proc(tab: auto): proc() =
return (proc() =
echo "Hello World"
)
)(tab)
So the error is not referring to the proc you’re returning, but to the proc generated by capture. If you replace the auto with Table[string, string] in the expanded code, it seems to work.