dstep icon indicating copy to clipboard operation
dstep copied to clipboard

Generated template with name conflict

Open buckle2000 opened this issue 4 years ago • 4 comments

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)

buckle2000 avatar Apr 25 '20 17:04 buckle2000

Hmm, seems difficult to fix.

jacob-carlborg avatar May 16 '20 09:05 jacob-carlborg

Is it possible to generate a constructor instead?

buckle2000 avatar May 16 '20 10:05 buckle2000

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?

jacob-carlborg avatar May 16 '20 11:05 jacob-carlborg

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.

buckle2000 avatar May 16 '20 11:05 buckle2000