Delegating bind statements
The following example outlines a problem that can arise when generic instantiations cross multiple different modules:
# module A
proc genericA*[T](x: T) =
mixin init
init(x)
import C
# module B
proc genericB*[T](x: T) =
# Without the `bind init` statement C's init proc is
# not available when `genericB` is instantiated:
bind init
genericA(x)
# module C
type O = object
proc init*(x: var O) = discard
# module main
import B, C
genericB O()
In module B has an init proc from module C in its scope that is not taken into account when genericB is instantiated which leads to the instantiation of genericA. The solution is to forward these symbols by a bind statement inside genericB.
当前内容版权归 nim-lang.org 或其关联方所有,如需对内容或内容相关联开源项目进行关注与资助,请访问 nim-lang.org .