[Issue 9165] New: Auto conversion from dynamic array to fixed size array at return

d-bugmail at puremagic.com d-bugmail at puremagic.com
Sun Dec 16 17:16:14 PST 2012


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

           Summary: Auto conversion from dynamic array to fixed size array
                    at return
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: enhancement
          Priority: P2
         Component: DMD
        AssignedTo: nobody at puremagic.com
        ReportedBy: bearophile_hugs at eml.cc


--- Comment #0 from bearophile_hugs at eml.cc 2012-12-16 17:16:13 PST ---
int[2] foo() {
    return [1, 2].dup;
}
int[2] bar() {
    int[2] __aux = [1, 2].dup;
    return __aux;
}
void main() {}


DMD 2.061alpha gives:

test.d(2): Error: cannot implicitly convert expression (_adDupT(&
D11TypeInfo_Ai6__initZ, [1, 2])) of type int[] to int[2u]


If possible I'd like to write code as in foo() instead of using a temporary
fixed sized array as in bar(). I presume in foo() the data needs to be copied
to the stack any way, so probably foo() should just be syntax sugar for bar().


The same problem happens for std.array.array():

int[2] spam() {
    return [1, 2].array();
}


But it doesn't happen for an array literal:

int[2] baz() {
    return [1, 2];
}

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