[Issue 21745] Closure created in struct constructor passed to class constructor is not heap allocated
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Mon Mar 22 16:19:30 UTC 2021
https://issues.dlang.org/show_bug.cgi?id=21745
--- Comment #5 from RazvanN <razvan.nitu1305 at gmail.com> ---
(In reply to FeepingCreature from comment #4)
> I think that's correct.
>
> Since it's a struct, it should save "this" by value though. typeof(this) is
> Foo, not Foo*.
I've investigated this a bit, but given my n00bism with the backend I did not
get very far. The issue seems to revolve around how struct values are passed
between stack frames. For example, if we add some fields to struct Foo, the
example runs correctly:
struct Foo
{
int i, l, k, t;
Bar bar;
this(int i)
{
this.i = i;
this.bar = new Bar({ return this.i; });
}
}
This is what I could come up with so far: at [1] the type of the this variable
is changed from `struct type` to a pointer, so this branch [2] is never taken.
I assume that the bug is somewhere inside el_bin [3] or el_una [4] since adding
more fields seems to make it work. I suspect that the bug has something to do
with how the struct is passed (via registers or a memcmp) and probably the
compiler forgets that a closure should be allocated in this case. I'm going to
try to take a deeper dive if somebody else doesn't beat me to it.
[1] https://github.com/dlang/dmd/blob/master/src/dmd/toir.d#L895
[2] https://github.com/dlang/dmd/blob/master/src/dmd/toir.d#L909
[3] https://github.com/dlang/dmd/blob/master/src/dmd/toir.d#L899
[4] https://github.com/dlang/dmd/blob/master/src/dmd/toir.d#L900
--
More information about the Digitalmars-d-bugs
mailing list