On Wednesday, 8 May 2024 at 12:29:05 UTC, Rene Zwanenburg wrote:
Interestingly enough C# used to have the same behaviour but MS
decided to go for a breaking change in C# 5; now it behaves as
most people expect.
Wow! I wonder if D would be willing to allow such a breaking
change with the
On Monday, 6 May 2024 at 16:41:38 UTC, Steven Schveighoffer wrote:
On Monday, 6 May 2024 at 06:29:49 UTC, Liam McGillivray wrote:
Delegates can be a pain, as they often have results different
from what one would intuitively expect. This can easily result
in bugs.
Here's a line that caused a
On Monday, 6 May 2024 at 16:41:38 UTC, Steven Schveighoffer wrote:
This is a very old issue:
https://issues.dlang.org/show_bug.cgi?id=2043 since "moved" to
https://issues.dlang.org/show_bug.cgi?id=23136
I would love to see a solution, but the workaround at least
exists!
-Steve
On Monday, 6 May 2024 at 06:29:49 UTC, Liam McGillivray wrote:
Delegates can be a pain, as they often have results different
from what one would intuitively expect. This can easily result
in bugs.
Here's a line that caused a bug that took me awhile to find:
```
foreach(card; unitCards)
On Monday, 6 May 2024 at 06:29:49 UTC, Liam McGillivray wrote:
Here's a line that caused a bug that took me awhile to find:
```
foreach(card; unitCards) card.submitted = delegate() =>
selectUnit(card.unit);
```
I think you can do:
```d
import std.algorithm.iteration : each;
On Monday, 6 May 2024 at 06:29:49 UTC, Liam McGillivray wrote:
This is because the delegate assignment causes the local `card`
variable to remain alive. The delegate that's assigned is
linked to this variable itself, not the value at the time that
the delegate is assigned.
This is
Delegates can be a pain, as they often have results different
from what one would intuitively expect. This can easily result in
bugs.
Here's a line that caused a bug that took me awhile to find:
```
foreach(card; unitCards) card.submitted = delegate() =>
selectUnit(card.unit);
```
Each