Hi,
after some time I got back playing with UDTCs - I know they are still experimental, but I consider them quite useful. The following code does not compile when I enable the last type:
import typetraits
type
HasZero = generic v
v.zero is int
proc test(self: HasZero): int = self.zero
type
Foo[Z:HasZero] = object {.inheritable.}
zz: ref Z
proc test(self: Foo):int = test(self.zz[])
type
MyZero = object
data: int
proc make(self: var MyZero) =
self.data = 10
proc zero(self: MyZero):int = self.data
type
MyFoo = Foo[MyZero]
proc make(self: var MyFoo) =
new(self.zz)
make(self.zz[])
var
x: MyFoo
make(x)
echo test(x)
when false: # when true: does not compile
type
FooBar[Z:HasZero] = object of Foo[Z]
data: int
the compiler complains here with Error: cannot instantiate Foo got: (typedesc[Z]) but expected: (Z)
Is this a bug, or misunderstanding from my side ?
cheers, Adrian.