Made Game For the Raylib 6.0 Jam
Steven Schveighoffer
schveiguy at gmail.com
Mon Jul 20 02:49:48 UTC 2026
On Sunday, 19 July 2026 at 22:49:04 UTC, Dennis wrote:
> On Sunday, 12 July 2026 at 22:13:50 UTC, Kapendev wrote:
>> **Find The Bug Section**
>>
>> ```d
>> if (minutes == 1) text = "You played for...\n {} minute\n {}
>> seconds",
>> text = text.fmt(minutes, seconds);
>> ```
>
> I thought it was going to be that `text = x;` gets transformed
> to `text(x);` through property syntax, but what is that comma
> doing there and why does the compiler still allow this use of
> the comma operator?
Whoa. I too was confused but... I was trying it out, simplified
version:
```d
int x = 1;
x = 2, x = 3;
```
This compiles and x is assigned to 3.
So what is happening? It turns out the comma operator is lower
precedence than assignment (one of the few). So this statement
really is:
```d
(x = 2), (x = 3);
```
So the actual result of the comma operator is not being used.
If you change to:
```d
x = (2, x = 3);
```
you will get the error.
This kinda makes sense, considering the one place where we
normally accept comma usage is in for-loops, and an increment
clause can look like this.
-Steve
More information about the Digitalmars-d
mailing list