On Wednesday, 31 March 2021 at 04:49:50 UTC, novice3 wrote:
On Tuesday, 30 March 2021 at 21:53:34 UTC, Basile B. wrote:
struct Typedef(TBase)
{
   TBase payload;
   alias payload this;
}

alias Xobj = Typedef!(void*);

This is how std.typecons.Typedef made, IMHO.

The problem is this code generate struct with name "Typedef!(void*)",
then compiler show this name (not "Xobj") in messages:

https://run.dlang.io/is/eEI2yC

  void* bad;
  foo(bad);

Error: function foo(Typedef!(void*) obj) is not callable using argument types (void*) cannot pass argument bad of type void* to parameter Typedef!(void*) obj

yeah template instances are identified using the parameters identifiers, then the alias is just a syntactic shortcut to that, not producing a new symbol with a unique mangle... but the message is correct assuming you want void* to be rejected.

That being said you can still use a string mixin if the messages have to be correct

---
string genTypeDef(TBase)(string name)
{
return "struct " ~ name ~ "{" ~ TBase.stringof ~ " payload; alias payload this;}";
}

mixin(genTypeDef!(void*)("Xobj"));

void foo (Xobj obj) {}
---

Reply via email to