www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 535] New: writef doesn't work on interfaces

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

           Summary: writef doesn't work on interfaces
           Product: D
           Version: 0.174
          Platform: PC
        OS/Version: Windows
            Status: NEW
          Severity: normal
          Priority: P2
         Component: Phobos
        AssignedTo: bugzilla digitalmars.com
        ReportedBy: smjg iname.com


If writef is fed an argument of an interface type, it just throws a
FormatError.

----------
import std.stdio;

interface Qwert {}

class Yuiop : Qwert {
    char[] toString() {
        return "asdfg";
    }
}

void main() {
    Qwert hjkl = new Yuiop;

    writefln(hjkl);
    writefln("%s", hjkl);
}
----------
Error: std.format formatArg
----------

It should use the object's toString property.  True, interfaces don't extend
Object and so don't have toString as such, but what could be more sensible than
casting it to an Object and then treating it in the same way?

Adding char[] toString() to the interface makes no difference.


-- 
Nov 16 2006
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=535


thomas-dloop kuehne.cn changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Severity|normal                      |enhancement
         OS/Version|Windows                     |All




-- 
Apr 29 2007
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=535


wbaxter gmail.com changed:

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




------- Comment #1 from wbaxter gmail.com  2007-12-05 23:41 -------
I'd say this is an outright bug.  It can't cast to Object because it could be a
COM interface, but if the interface explicitly has a toString method, then
writef should definitely call it rather than throwing an exception.


-- 
Dec 05 2007
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=535





------- Comment #2 from smjg iname.com  2007-12-06 13:04 -------
Surely it's not being a COM _interface_, but being a COM _object_ external to D
that would be a problem, right?

I suppose the question is whether the runtime can determine if it's a D object.
 If so, the TypeInfo for interfaces could define this behaviour:  If the
interface defines a suitable toString, use it.  Otherwise, see at runtime
whether the interface instance is a D object.  If so, convert it to an Object
and use its toString, otherwise throw an exception.

If this runtime checking isn't possible (or isn't worth the implementation
cost), then having a documented requirement that the interface defines a
toString for it to work is a possibility, but it still has its drawbacks....


-- 
Dec 06 2007
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=535


dsimcha yahoo.com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |2korden gmail.com




------- Comment #3 from dsimcha yahoo.com  2009-03-27 19:43 -------
*** Bug 2200 has been marked as a duplicate of this bug. ***


-- 
Mar 27 2009
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=535


Andrei Alexandrescu <andrei metalanguage.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |ASSIGNED
                 CC|                            |andrei metalanguage.com
         AssignedTo|nobody puremagic.com        |andrei metalanguage.com


-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Oct 11 2009
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=535


Andrei Alexandrescu <andrei metalanguage.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|ASSIGNED                    |RESOLVED
         Resolution|                            |FIXED


--- Comment #4 from Andrei Alexandrescu <andrei metalanguage.com> 2010-09-13
19:44:38 PDT ---
http://www.dsource.org/projects/phobos/changeset/1996

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