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

d-bugmail at puremagic.com d-bugmail at puremagic.com
Wed Oct 9 21:54:12 PDT 2013


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



--- Comment #7 from Kenji Hara <k.hara.pg at gmail.com> 2013-10-09 21:54:03 PDT ---
The inconsistency comes from the incomplete fix of bug 7019.

struct Agg(T) { T val; }
void main()
{
    int[3] sa = 1;                // 1a, OK
    auto agg1 = Agg!(int[3])(1);  // 1b, OK

    struct S { this(int) {} }
    S s = 1;                      // 2a, OK, by fixing issue 7019
    auto agg2 = Agg!S(1);         // 2b
}

Since long time ago, 1a and 1b has been allowed.

On the other hand, from 2.061, 2a has formally become a part of the language
spec, by fixing issue 7019.

However, currently 2b is still disallowed.

Because, when I had wrote a compiler patch for bug 7019, I had thought that
accepting it might cause some ambiguity on multi-dimentional array
initializing.

  struct S { this(int) {} }
  S[2][2] sa = [1, 2];
  // exactly same as:
  //      sa = [[S(1), S(2)], [S(1), S(2)]]
  // or:  sa = [[S(1), S(1)], [S(2), S(2)]]
  // ?

But recently, I found a new consistent rule to resolve the ambiguity. Based on
the rule in my brain, the 2b case would also be accepted.

Therefore, the current inconsistency is a bug to me. If T t = val; is accepted,
the struct literal syntax Aggr!T(val) should also be accepted.

-- 
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