[Issue 12032] New: One case of refused slicing assignment to fixed size array

d-bugmail at puremagic.com d-bugmail at puremagic.com
Wed Jan 29 08:31:21 PST 2014


https://d.puremagic.com/issues/show_bug.cgi?id=12032

           Summary: One case of refused slicing assignment to fixed size
                    array
           Product: D
           Version: D2
          Platform: x86
        OS/Version: Windows
            Status: NEW
          Keywords: rejects-valid
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: nobody at puremagic.com
        ReportedBy: bearophile_hugs at eml.cc


--- Comment #0 from bearophile_hugs at eml.cc 2014-01-29 08:31:21 PST ---
With dmd 2.065beta this compiles and runs with no errors:

int[2] foo() {
    int[] a = [1, 2, 3, 4];
    return a[0 .. 2]; // OK
}
void main() {}


This compies and runs with no errors:

void main() {
    int[] a = [1, 2, 3, 4];
    int[2] b;
    b[] = a[$ - 2 .. $]; // OK
}


While this code:

int[2] foo() {
    int[] a = [1, 2, 3, 4];
    return a[$ - 2 .. $]; // Error
}
void main() {}


Gives:

test.d(3): Error: cannot implicitly convert expression (a[__dollar -
2u..__dollar]) of type int[] to int[2]

I'd like this code to compile.

-- 
Configure issuemail: https://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------


More information about the Digitalmars-d-bugs mailing list