www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 5199] New: null implicitly converts to any other type on array assignment

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

           Summary: null implicitly converts to any other type on array
                    assignment
           Product: D
           Version: D2
          Platform: Other
        OS/Version: Windows
            Status: NEW
          Keywords: accepts-invalid, diagnostic
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: nobody puremagic.com
        ReportedBy: dsimcha yahoo.com



The following code compiles and shouldn't:

struct Foo {
    double num;
}

void main() {
    Foo[] foo = new Foo[5];
    foo[] = null;
}

It then fails at runtime with the following nonsensical error message:

object.Exception: lengths don't match for array copy

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Nov 10 2010
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=5199


bearophile_hugs eml.cc changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |bearophile_hugs eml.cc



It's an example of bug 3889

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Nov 10 2010
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=5199


Walter Bright <bugzilla digitalmars.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
                 CC|                            |bugzilla digitalmars.com
         Resolution|                            |INVALID



20:13:51 PST ---
null is a valid value for a slice, and the rvalue of the assignment is expected
to be a slice. It's a slice with 0 length (which is still a valid slice), and
for slice assignment to work the length of the lvalue must match the length of
the rvalue. The message is correct - the lengths don't match.

This is working as designed.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Nov 16 2010
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=5199




20:16:35 PST ---
Bearophile is correct that this is a duplicate of bug 3889, which is an
enhancement request.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Nov 16 2010
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=5199




21:34:06 PST ---
I'd rather say it's a dup of bug 3395.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Nov 16 2010
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=5199




21:39:09 PST ---
Disambiguation will make it hard to copy empty slices... well... such operation
is not needed too much either.
---
foo[]=(cast(Foo[])null)[]; //copy null slice
foo[]=null; //should not typecheck, expected foo[]=Foo(...);
---

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