www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 2082] New: Cannot convert char[] to string

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

           Summary: Cannot convert char[] to string
           Product: D
           Version: 2.012
          Platform: PC
        OS/Version: Linux
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: bugzilla digitalmars.com
        ReportedBy: jlquinn optonline.net


This is really ugly.  The following program:

void test(char[] s) {
  string t = s;
}

gives the following error:

junk2.d(2): Error: cannot implicitly convert expression (s) of type char[] to
invariant(char)[]

I haven't found a way around this yet.  It really should be handled as an
implicit conversion, with a copy being made under the covers as needed.


-- 
May 08 2008
next sibling parent BCS <ao pathlink.com> writes:
Reply to d-bugmail puremagic.com,

 http://d.puremagic.com/issues/show_bug.cgi?id=2082
 
 Summary: Cannot convert char[] to string
 Product: D
 Version: 2.012
 Platform: PC
 OS/Version: Linux
 Status: NEW
 Severity: normal
 Priority: P2
 Component: DMD
 AssignedTo: bugzilla digitalmars.com
 ReportedBy: jlquinn optonline.net
 This is really ugly.  The following program:
 
 void test(char[] s) {
 string t = s;
 }
 gives the following error:
 
 junk2.d(2): Error: cannot implicitly convert expression (s) of type
 char[] to invariant(char)[]
 
 I haven't found a way around this yet.  It really should be handled as
 an implicit conversion, with a copy being made under the covers as
 needed.
 

I think you need to use .idup
May 08 2008
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=2082





------- Comment #2 from jlquinn optonline.net  2008-05-08 17:23 -------
To me, this seems like it's going to clutter commonly occurring code.  Since
char[] and string are similar, and the language is generally trying to treat
them like built-in types, I would hope this kind of conversion was transparent
most of the time.


-- 
May 08 2008
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=2082


kamm-removethis incasoftware.de changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|                            |INVALID




------- Comment #3 from kamm-removethis incasoftware.de  2008-05-09 01:02
-------
This is desired behaviour. Use idup() to make a new invariant copy or use a
cast (via assumeUnique from std.contracts?) if you can guarantee the data is
invariant.


-- 
May 08 2008
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=2082





------- Comment #4 from kamm-removethis incasoftware.de  2008-05-09 01:03
-------
*** Bug 2083 has been marked as a duplicate of this bug. ***


-- 
May 08 2008