Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes an issue where two types can collide in the cgen #23937

Open
wants to merge 7 commits into
base: devel
Choose a base branch
from

Conversation

jmgomez
Copy link
Collaborator

@jmgomez jmgomez commented Aug 10, 2024

When generating a header with --header and then using it from another Nim project to import the generated types, generic instances can collide and produce an error.
i.e. typedef MyGeneric[TypeA] typename typedef MyGeneric[TypeB] typename signature here cant be the same as they are different types.

This issue can be avoided by using the Nim type as part of the name which is what this PR does.

Update:
Encode types so MyClass[T] becomes typedef MyClass<NI> TY_MyClass_int; instead of Ty_QjHlYnbKApuWy39cRg7R7dw

Update 2:

struct seq_int { //seq[int]
  NI len; seq_int_Content* p;
};
struct TypeTest_int { // TypeTest[T] = object 
    NI Whatever;
};
struct cpptest_ObjectType { //ObjectType = object
    NI32 x;
};
struct Table_intint { //Table[int, int]
    char dummy;
};

When generating a header with `--header` and then using it from another Nim project to import the generated types, generic instances can collide and produce an error i.e. `typedef MyGeneric[TypeA] typename` `typedef MyGeneric[TypeB] typename` `signature` here cant be the same as they are different types.  This issue can be avoided by using the Nim type as part of the name which is what PR does.
Encode types so   `MyClass[T]` becomes `typedef MyClass<NI>  TY_MyClass_int;` instead of `Ty_QjHlYnbKApuWy39cRg7R7dw`
@Araq
Copy link
Member

Araq commented Aug 22, 2024

Tests are red though.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants