Open
Description
Example
type
MyValue[T] = object
a, b: T
proc value[T](a, b: T): MyValue[T] =
result.a = a
result.b = b
let
a: cint = 10
b: cint = 10
# -- C Code Error Here --
# -- type cint {.importc: "int".} = int32
v0: MyValue[int32] = value(a, b) # MyValue[cint]
v1: MyValue[int32] = value(b, a) # MyValue[cint]
echo v0.a - v0.b
echo v1.a - v1.b
Actual Output
~/.cache/nimskull/type_d/@mtype.nim.c: In function ‘NimMainModule’:
~/.cache/nimskull/type_d/@mtype.nim.c:109:23: error: incompatible types when assigning to type ‘_I7MyValue_16777236’ from type ‘_I7MyValue_16777231’
109 | v0__type_24 = _7;
| ^~
~/.cache/nimskull/type_d/@mtype.nim.c:113:23: error: incompatible types when assigning to type ‘_I7MyValue_16777236’ from type ‘_I7MyValue_16777231’
113 | v1__type_30 = _8;
Expected Output
i think it should be a type mismatch error regarding using int16 or other implicit convertible types marks as type mismatch error
Possible Solution
without using a generic proc and use object initialization syntax instead it compiles
v0: MyValue[int32] = MyValue[cint](a: a, b: b)
v1: MyValue[int32] = MyValue[cint](a: b, b: a)