www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 13700] New: Rejected valid conversion from slice to fixed

https://issues.dlang.org/show_bug.cgi?id=13700

          Issue ID: 13700
           Summary: Rejected valid conversion from slice to fixed size
                    array
           Product: D
           Version: D2
          Hardware: x86
                OS: Windows
            Status: NEW
          Keywords: rejects-valid
          Severity: enhancement
          Priority: P1
         Component: DMD
          Assignee: nobody puremagic.com
          Reporter: bearophile_hugs eml.cc

I think this whole program should be accepted:


void main() {
    int[char[2]] aa;
    string s = "hello";
    immutable i = 1;
    aa[s[i .. i + 2]] = 1; // OK
    auto j = 1;
    aa[s[j .. j + 2]] = 1; // Error
    char[2] aux = s[j .. j + 2];
    aa[aux] = 1;           // OK
}


DMD 2.067alpha gives:

test.d(7,9): Error: cannot implicitly convert expression
(s[cast(uint)j..cast(uint)(j + 2)]) of type string to char[2]

--
Nov 08 2014