[Issue 11206] static array can be implicitly built from items, when nested in aggregate

d-bugmail at puremagic.com d-bugmail at puremagic.com
Thu Oct 10 01:32:09 PDT 2013


http://d.puremagic.com/issues/show_bug.cgi?id=11206


Maxim Fomin <maxim at maxim-fomin.ru> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|accepts-invalid             |
           Severity|normal                      |enhancement


--- Comment #12 from Maxim Fomin <maxim at maxim-fomin.ru> 2013-10-10 01:32:06 PDT ---
(In reply to comment #11)
> (In reply to comment #9)
> > As I have mentioned previously, there is no inconsistency because you
> > implicitly assuming that struct literal/constructors can be recursive or
> > 'nested' in some sense. If you mean allowing AGG!S ts1 = AGG!S(1); in original
> > example, then this is a minor enhancement.
> 
> I knot that it is an enhancement (eg. bug 7255), but I think it's necessary to
> increase consistency between static array and user-defined struct type, and
> it's important for more expressiveness on initializing.
> 
> The start of my thought ----
> Currently, BigInt accepts built-in integers as the "valid initializer".
> 
>   BigInt num = 1;
> 
> This is expressive syntax. But, when you declare a multi-dimensional array of
> BigInt, it would become too verbose.
> 
>   BigInt[128] sa = [
>       BigInt(1), BigInt(2), BigInt(3), BigInt(4),
>       BigInt(5), BigInt(6), BigInt(7), BigInt(8),
>       ...
>   ];
> 
> If T t = v; is allowed, array initializer should also allow T[n] tsa = [v1, v2,
> ...]; After the enhancement implemented, we will be able to write the BigInt
> array declaration as:
> 
>   BigInt[128] sa = [1, 2, 3, 4, 5, 6, 7, 8, ..., 128];
> 
> ---- The end of my thought

OK. I agree that there is room for improving support for implicit construction.

> I think we could apply the same rule to the relation of struct literal syntax
> arguments and corresponding struct field type.
> 
>   Agg!S agg = Agg!S(1);  // #1
>   S[1] ssa = [1];    // #2
> 

It looks like when you are speaking about struct literal syntax you mean both
struct literal and struct constructors (probably even opCall). It seems that
Agg!S(1) would be valid either if there is constructor taking int or first
member is integer type. Do you consider documenting it after merging
corresponding pull?

> - In #1, the struct field Agg!S.val is initialized by the corresponding value 1
> which is in the struct literal argument list.
> - In #2, the array element ssa[1] is initialized by the corresponding value 1
> which is in the array initializer argument list.
> 
> In both case, if the initialized storage typed S accepts the corresponding
> value 1 *as the valid initializer*, the composite array/struct initializing
> should also work.
> 
> Additional note: The following code already works currently.
> 
>   Agg!S aggr2 = {val:1};   // struct initializer syntax

OK. I changed type of the issue to show it is enhacement now.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------


More information about the Digitalmars-d-bugs mailing list