Thread overview
Is it possible to assign a Comma Expression to a variable?
Nov 29, 2022
Lucian Danescu
Nov 29, 2022
H. S. Teoh
Nov 29, 2022
Vladimir Panteleev
November 29, 2022

To give some context, D-Scanner has a check that warns against assigning a comma expression to a variable. Example:

a = (foo(), bar(), 1); // warn here

This check was implemented a while back, and from what I can see, currently assigning a comma expression results in a compilation error, hence that check in D-Scanner would not be necessary anymore.

I just wanted to make sure that it is impossible to assign a comma expression to a variable, or if it is possible, can someone please clarify when and maybe give an example?

November 29, 2022
On Tue, Nov 29, 2022 at 09:24:43PM +0000, Lucian Danescu via Digitalmars-d wrote:
> To give some context, D-Scanner has a check that warns against assigning a comma expression to a variable. Example:
> 
> ```
> a = (foo(), bar(), 1); // warn here
> ```
> 
> This check was implemented a while back, and from what I can see, currently assigning a comma expression results in a compilation error, hence that check in D-Scanner would not be necessary anymore.
> 
> I just wanted to make sure that it is impossible to assign a comma expression to a variable, or if it is possible, can someone please clarify when and maybe give an example?

No it's not possible to assign a comma expression to a variable. That has been deprecated years ago, and as far as I can tell generates a flat out compile error now.

In the future, comma syntax may be extended to tuples.


T

-- 
Help a man when he is in trouble and he will remember you when he is in trouble again.
November 29, 2022

On Tuesday, 29 November 2022 at 21:24:43 UTC, Lucian Danescu wrote:

>

I just wanted to make sure that it is impossible to assign a comma expression to a variable, or if it is possible, can someone please clarify when and maybe give an example?

As a workaround, you can use a function:

https://github.com/CyberShadow/ae/blob/86b016fd258ebc26f0da3239a6332c4ebecd3215/utils/meta/package.d#L526-L554