type
VALUE = object
d: uint32
#proc init(v: var VALUE) = # working code
# v.d = 3
proc init(v: var VALUE | ptr VALUE) =
when v is ptr VALUE:
v[].d = 1
else:
v.d = 2 # compile error
var v: VALUE
v.init()
echo repr v
testRepr.nim(28, 2) template/generic instantiation of `init` from here testRepr.nim(25, 6) Error: 'v.d' cannot be assigned to
This is my mistake or compiler?
It's a compiler bug. Probably the var is not corretly seen when it's not the top modifier.
For example I think var (int | uint) would work but var int | int would not.
I suggest you use overloading instead.