[Issue 20876] DMD gives out not so helpful compile error

d-bugmail at puremagic.com d-bugmail at puremagic.com
Fri May 29 14:45:40 UTC 2020


https://issues.dlang.org/show_bug.cgi?id=20876

--- Comment #6 from kinke <kinke at gmx.net> ---
(In reply to RazvanN from comment #4)
> So, to conclude, by the current language rules the error is correct.
> 
> The fix in this situation would be to annotate the copy constructor of Bar
> with `inout`: this(ref inout(Bar)) inout . That will make the code to
> compile.
> 
> But I agree that the error could be improved.

Thx for the explanation. - I think this really needs some work. So currently,
this fails for both

struct Bar { this(ref Bar) {} }
struct Bar { this(const ref Bar) {} }

because the compiler tries to generate an inout copy ctor for

struct Foo { Bar _bar; }

Instead of disabling it completely if that fails, I think it should try to fall
back to a mutable or const copy ctor, propagating the limitations of its
fields.

--


More information about the Digitalmars-d-bugs mailing list