www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 7664] New: Problem with fixed-sized associative array key assignment

reply d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=7664

           Summary: Problem with fixed-sized associative array key
                    assignment
           Product: D
           Version: D2
          Platform: x86
        OS/Version: Windows
            Status: NEW
          Keywords: rejects-valid
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: nobody puremagic.com
        ReportedBy: bearophile_hugs eml.cc



I think this code has to be valid:



void main() {
    auto s = "hello";
    uint[immutable char[4]] aa;
    aa[s[0 .. 4]] = 0;
}


But DMD 2.059head gives:

test.d(4): Error: cannot implicitly convert expression (s[0u..4u]) of type
string to immutable(char[4u])

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Mar 07 2012
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=7664




Compiler can calculate the length for s[0 .. 4] in compile time, because both
lower bound and upper bound are constant expressions. So converting it to
static array type is possible.

But, currently, the slice of an array expression is *always* typed as dynamic
array type.
Therefore it is a constant-folding enhancement, not a bug.

Bug 7665 will also settle down to the same mechanism.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Mar 24 2012
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=7664


bearophile_hugs eml.cc changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Severity|normal                      |enhancement




 Compiler can calculate the length for s[0 .. 4] in compile time, because both
 lower bound and upper bound are constant expressions. So converting it to
 static array type is possible.
 
 But, currently, the slice of an array expression is *always* typed as dynamic
 array type.
 Therefore it is a constant-folding enhancement, not a bug.
Thank you for your answers. I convert this to enhancement request then. I think such constant-folding is useful to remove some run-time tests and speed up other code that uses slices. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Mar 24 2012
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=7664





 Thank you for your answers. I convert this to enhancement request then.
 
 I think such constant-folding is useful to remove some run-time tests and speed
 up other code that uses slices.
In really special case, D allows such conversion from dynamic array type to static array type. See following: void foo(immutable(char)[4] s){} void main() { static assert(is(typeof("test") == immutable(char)[])); foo("test"); // immutable(char)[] to immutable(char)[4] foo(['t','e','s','t']); // immutable(char)[] to immutable(char)[4] } So there seems to be enough reasoning for this enhancement. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Mar 24 2012