Simple example:
struct S(T)
{
T *t;
immutable(S) foo(T* x) { return S(x);}
}
S!int s;
The error message is as follows:
Error: cannot implicitly convert expression (S(x)) of type S!int to immutable(S!int)
Reasonable, straightforward message. But it starts breaking down as we add ctor and dtor:
struct S(T)
{
T *t;
this(T *x) { t = x;}
immutable(S) foo(T* x) { return S(x);}
}
Error: cannot implicitly convert expression (S(null).this(x)) of type S!int to immutable(S!int)
Not sure where the S(null).this(x) comes from. Add a dtor and it's even worse:
struct S(T)
{
T *t;
this(T *x) { t = x;}
~this() {}
immutable(S) foo(T* x) { return S(x);}
}
Error: cannot implicitly convert expression (( S!int __slS51 = S(null);
, __slS51).this(x)) of type S!int to immutable(S!int)
That carriage return is actually in the output. I don't even think that's valid D code (semicolon followed by comma).
All three of these should look like the first one.
Note that just a dtor does not affect the output.
Tested as far back as 2.067.1
Comment #1 by razvan.nitu1305 — 2022-10-13T08:27:33Z
The destructor one has been fixed so that compiler internals are not spilled out anymore: "cannot implicitly convert expression (S(x)) of type S!int to immutable(S!int)". However, the constructor one still outputs `S(null).this(x)`. That is mainly because that is what the compiler rewrites `S(x)` so that it is processed as a method call. Not sure if this could be improved.
Comment #2 by robert.schadek — 2024-12-13T18:45:50Z