DIP 1031--Deprecate Brace-Style Struct Initializers--Community Review Round 1 Discussion

IGotD- nise at nise.com
Thu Feb 13 15:49:07 UTC 2020


On Thursday, 13 February 2020 at 13:05:19 UTC, Steven 
Schveighoffer wrote:
>
> That page is *really* old. I think what Mike meant to say is 
> that struct initializers and struct literals are both disabled 
> once a constructor or opCall function is present.
>
> So in essence, the above struct S could NEVER be initialized 
> except via constructor or with it's .init value. Having the 
> named parameter DIP accepted means that now the constructor 
> becomes possible to call like the initializer, assuming you 
> gave bp and ap default values.
>
> -Steve

Isn't that a bit restrictive? Wouldn't you like to have a 
constructor and sometimes parenthesis style initialization? With 
using parenthesis for everything there will be an ambiguity. In 
that case keeping () for constructor and {} for initialization 
would make it clear what the programmer wants.

If the compiler cannot match a constructor it can go on and use 
initialization instead. Would this be too allowing and lead to 
that programmer errors are missed?


More information about the Digitalmars-d mailing list