Skip to content

c code error type mismatch on generic objects with same T parameters but one has a T from FFI #1431

Open
@mrgaturus

Description

@mrgaturus

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)

Additional Information

References

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingcompiler/semRelated to semantic-analysis system of the compiler

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions