www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 13228] New: Value range analysis for the length of slices

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

          Issue ID: 13228
           Summary: Value range analysis for the length of slices
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Severity: enhancement
          Priority: P1
         Component: DMD
          Assignee: nobody puremagic.com
          Reporter: bearophile_hugs eml.cc

I suggest to introduce in D a value range analysis and propagation for the
length of slices, it should allow code like (currently refused):


void foo(int[100]) {}
ubyte x = 100;
void main() {
    const int[] a = new int[x];
    foo(a);
}


That currently gives:

test.d(5,8): Error: function test.foo (int[100] _param_0) is not callable using
argument types (const(int[]))


That is comparable to code like this (that is accepted by dmd 2.066beta5):

void foo(ubyte) {}
ubyte x = 100;
void main() {
    const int a = x;
    foo(a);
}

--
Jul 30 2014