www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 5074] New: array(immutable(int)[]) ==> int[]

reply d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=5074

           Summary: array(immutable(int)[]) ==> int[]
           Product: D
           Version: D2
          Platform: x86
        OS/Version: Windows
            Status: NEW
          Keywords: rejects-valid
          Severity: normal
          Priority: P2
         Component: Phobos
        AssignedTo: nobody puremagic.com
        ReportedBy: bearophile_hugs eml.cc


--- Comment #0 from bearophile_hugs eml.cc 2010-10-18 19:02:48 PDT ---
This is more an enhancement request than a bug report.

In my opinion an array() applied on an array has to act like "dup", just like
array(static_array) returns a dynamic array. So I think array(immutable(int)[])
has to return an int[].

With DMD 2.049 array(immutable(int)[]) doesn't work:


import std.array: array;
void main() {
    int[4] a0 = [2, 3, 1, 4];
    static assert(is(typeof(array(a0)) == int[])); // OK
    immutable(int)[] a1 = [2, 3, 1, 4];
    int[] a2 = a1.dup;
    int[] a3 = array(a1); // ERROR
}


Errors generated:

...\dmd\src\phobos\std\array.d(64): Error: result[i] isn't mutable
...\dmd\src\phobos\std\array.d(7): Error: template instance
std.array.array!(immutable(int)[]) error instantiating
test.d(7): Error: cannot implicitly convert expression (array(a1)) of type
immutable(int)[] to int[]

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Oct 18 2010
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=5074


Andrei Alexandrescu <andrei metalanguage.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |andrei metalanguage.com


--- Comment #1 from Andrei Alexandrescu <andrei metalanguage.com> 2010-10-19
06:18:19 PDT ---
to!(int[])(a) should take care of that.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Oct 19 2010
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=5074



--- Comment #2 from bearophile_hugs eml.cc 2010-10-19 09:41:54 PDT ---
(In reply to comment #1)
 to!(int[])(a) should take care of that.
There are also const casts: array(cast(int[])a1) But the design point of array() is to digest anything you may iterate, and produce a dynamic array. So I think array(immutable(int)[]) should not require casts or to!(). -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Oct 19 2010