www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 9165] New: Auto conversion from dynamic array to fixed size array at return

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 puremagic.com
        ReportedBy: bearophile_hugs eml.cc



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: -------
Dec 16 2012