Thread overview
[Issue 15355] unstable operator overloading with comma expression
Dec 03, 2015
Ketmar Dark
Dec 06, 2015
Infiltrator
Dec 06, 2015
ZombineDev
Dec 17, 2022
Iain Buclaw
Jun 28, 2023
RazvanN
December 03, 2015
https://issues.dlang.org/show_bug.cgi?id=15355

Ketmar Dark <ketmar@ketmar.no-ip.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |ketmar@ketmar.no-ip.org

--
December 06, 2015
https://issues.dlang.org/show_bug.cgi?id=15355

Infiltrator <lt.infiltrator@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |lt.infiltrator@gmail.com

--- Comment #1 from Infiltrator <lt.infiltrator@gmail.com> ---
This might be surprising behaviour; but I think that it fits with what the comma operator does.

(a, b) gets evaluated as do a, discard, do b and return.

So, in this case:
(1, s2[0]) = 1
Evaluate 1 and discard just does nothing.  Evaluate s2[0] and return gives us a
ref to s2.y.  Only then does the = 1 take effect, so we end up with (ref to
s2.y) = 1.

So I don't think that there is actually a problem with the operator overloading in this case.

As for whether or how this quirk should be fixed, I'm afraid that I can't really say.

--
December 06, 2015
https://issues.dlang.org/show_bug.cgi?id=15355

ZombineDev <petar.p.kirov@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |petar.p.kirov@gmail.com

--- Comment #2 from ZombineDev <petar.p.kirov@gmail.com> ---
I think it would be more appropriate if the compiler raised an ambiguity error, because the behavior is tricky and can lead to hard to track bugs.

If the opIndexAssign is defined, than opIndex that returns a reference should be disallowed, or at least opIndex that returns a mutable (assignable) reference should be.

--
February 15, 2016
https://issues.dlang.org/show_bug.cgi?id=15355

hsteoh@quickfur.ath.cx changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |hsteoh@quickfur.ath.cx

--- Comment #3 from hsteoh@quickfur.ath.cx ---
The comma operator should be killed with extreme prejudice.

--
December 17, 2022
https://issues.dlang.org/show_bug.cgi?id=15355

Iain Buclaw <ibuclaw@gdcproject.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Priority|P1                          |P3

--
June 28, 2023
https://issues.dlang.org/show_bug.cgi?id=15355

RazvanN <razvan.nitu1305@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
                 CC|                            |razvan.nitu1305@gmail.com
         Resolution|---                         |WONTFIX

--- Comment #4 from RazvanN <razvan.nitu1305@gmail.com> ---
The comma operator is not supported anymore in the frontend. The code now yields:

test.d(24): Error: using the result of a comma expression is not allowed

--