You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When a type is defined to be generic on an object type, but is not actually using that type in its definition, as in Foo[T] = object (T is not used in the body of Foo[T]), there are compiler errors when trying to access the generic type in a proc. It seems that the only a single implementation is generated for the different T in that case, leading to C compilation errors when multiple different implementations are requested in a single compilation unit.
Example
typeFoo[T] =objectBar[F: Foo] =object
c: proc(t: F.T)
proccb[F](v: Bar[F]) =
v.c(default(F.T))
type
X =object
x: uint32
Y =object
x: uint32proccbX(v: X) =discardproccbY(v: Y) =discardlet
x =Bar[Foo[X]](c: cbX)
y =Bar[Foo[Y]](c: cbY)
x.cb()
y.cb()
Current Output
error: passing 'tyObject_Y__U7uoXYJsXAmQ0DnkqRcTeA' (aka 'struct tyObject_Y__U7uoXYJsXAmQ0DnkqRcTeA') to parameter of incompatible type 'tyObject_X__nhXs9ay3Yu0ODg9bF6LB8cRA' (aka 'struct tyObject_X__nhXs9ay3Yu0ODg9bF6LB8cRA')
nimZeroMem((void*)(&T1_), sizeof(tyObject_Y__U7uoXYJsXAmQ0DnkqRcTeA)); v.c.ClE_0? v.c.ClP_0(T1_, v.c.ClE_0):((TM__cz1FP2xNs9aBzwtJ0lyd4Jg_8)(v.c.ClP_0))(T1_);
^~~
1 error generated.
Expected Output
0
0
Possible Solution
As a workaround, use T in the definition of Foo, e.g., Foo[T] = (T,) instead of Foo[T] = object.
Second workaround is to only ever use a single instantiation in a compilation unit, e.g., put x and y into separate programs. The problem only occurs when there are multiple instantiations of different types.
Additional Information
% nim -v
Nim Compiler Version 1.2.16 [MacOSX: amd64]
Compiled at 2022-02-14
Copyright (c) 2006-2020 by Andreas Rumpf
git hash: c6a9f27b3e36bae9aacec1bd6c37893fb98fd33f
active boot switches: -d:release
The text was updated successfully, but these errors were encountered:
When a type is defined to be generic on an
object
type, but is not actually using that type in its definition, as inFoo[T] = object
(T
is not used in the body ofFoo[T]
), there are compiler errors when trying to access the generic type in aproc
. It seems that the only a single implementation is generated for the differentT
in that case, leading to C compilation errors when multiple different implementations are requested in a single compilation unit.Example
Current Output
Expected Output
Possible Solution
T
in the definition ofFoo
, e.g.,Foo[T] = (T,)
instead ofFoo[T] = object
.x
andy
into separate programs. The problem only occurs when there are multiple instantiations of different types.Additional Information
The text was updated successfully, but these errors were encountered: