www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Is it possible to assign a Comma Expression to a variable?

reply Lucian Danescu <lucidanescu28 yahoo.com> writes:
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?
Nov 29 2022
next sibling parent "H. S. Teoh" <hsteoh qfbox.info> writes:
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.
Nov 29 2022
prev sibling parent Vladimir Panteleev <thecybershadow.lists gmail.com> writes:
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
Nov 29 2022