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

Generated template with name conflict #253

Open
buckle2000 opened this issue Apr 25, 2020 · 4 comments
Open

Generated template with name conflict #253

buckle2000 opened this issue Apr 25, 2020 · 4 comments

Comments

@buckle2000
Copy link

Using the same example as #252, dstep would genreate the following code:

extern (D) auto uiControl(T)(auto ref T this)
{
    return cast(uiControl*) this;
}
struct uiControl
{
  // omitted
}

This will not compile in D

source/ui.d(83,17): Error: template ui.uiControl(T)(auto ref T that) conflicts with struct ui.uiControl at source/ui.d(64,1)
@jacob-carlborg
Copy link
Owner

Hmm, seems difficult to fix.

@buckle2000
Copy link
Author

Is it possible to generate a constructor instead?

@jacob-carlborg
Copy link
Owner

jacob-carlborg commented May 16, 2020

I don't think so. A construct would return the type it's defined in. While this macro returns a pointer to uiControl.

DStep could detect the naming conflict and choose to rename one of the symbols.

BTW, how is this intended to be used?

@buckle2000
Copy link
Author

buckle2000 commented May 16, 2020

I think libui (in C) has its own OOP inheritance system. There are functions like void setChild(uiControl* child) and you can pass uiControl(window) to it. Probably some pointer magic there.
For my D binding, I renamed that to toControl and it works.

Original C code:

struct uiControl {
	...
};
#define uiControl(this) ((uiControl *) (this))

I hate macros.

Maybe dstep should add underscore after names when conflict happens and show a warning.

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

No branches or pull requests

2 participants