[Issue 9120] New: Uniform construction for array types

d-bugmail at puremagic.com d-bugmail at puremagic.com
Thu Dec 6 16:51:49 PST 2012


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

           Summary: Uniform construction for array types
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: enhancement
          Priority: P2
         Component: DMD
        AssignedTo: nobody at puremagic.com
        ReportedBy: k.hara.pg at gmail.com


--- Comment #0 from Kenji Hara <k.hara.pg at gmail.com> 2012-12-06 16:51:45 PST ---
Spin-off issue from bug 9112.

In current, array types does not have consistency between literal syntax and
`new` syntax.

void maiin() {
  // dynamic array
  int[] da1 = [1,2,3];  // literal syntax
//int[] da2 = int[](1,2,3);  // not allowed
    // because dynamic array is *always* allocated in heap?
  int[] da3 = new int[](3);  // heap-allocated int array has length 3.
    // but, all elements in da2 initialized with int.init.
    // we cannot give initializing elements in use of new syntax.
  int[] dax = new int[3];  // special syntax. This creates int[] has length 3.

  int[3] sa1 = [1,2,3];  // literal syntax
//int[3] sa2 = int[3](1,2,3);  // not allowed
//int[3]* sa3a = new int[3];  // impossible
  alias T = int[3];
//int[3]* sa3b = new T;.  // Error: new can only create structs, dynamic arrays
or class objects, not int[3u]'s
    // -> special syntax for dynamic array blocks this...

  int[string] aa1 = ["a":1, "b":2];  // literal syntax
//int[string] aa1 = int[string]("a":1, "b":2);  // not allowed
//int[string] aa2 = new int[string];  // not allowed
}

This is not serious language flaw, but I feel it is desirable which have
consistent syntax.

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