Thread overview
[Issue 2200] New: std.string.format behaves wrong when passing an interface reference
Jul 07, 2008
d-bugmail
Jul 07, 2008
d-bugmail
Mar 28, 2009
d-bugmail
July 07, 2008
http://d.puremagic.com/issues/show_bug.cgi?id=2200

           Summary: std.string.format behaves wrong when passing an
                    interface reference
           Product: D
           Version: unspecified
          Platform: PC
        OS/Version: Windows
            Status: NEW
          Severity: normal
          Priority: P2
         Component: Phobos
        AssignedTo: bugzilla@digitalmars.com
        ReportedBy: 2korden@gmail.com


Current std.string.format implementation throws an exception if an interface reference is passed to it.Although interfaces don't derive from an Object, an attempt to cast to an Object should be made, and no exception should be thrown unless the cast was unsuccessful.

*Or* it should be a compile-time error to pass a reference to interface to the function.

module test;

interface I {}
class C : I {}

C c = new C();
I i = c;
Object o = cast(Object)i;

try { writefln( format(c) ); } catch (Exception e) { writefln(e); }
try { writefln( format(i) ); } catch (Exception e) { writefln("Error: ", e); }
try { writefln( format(o) ); } catch (Exception e) { writefln(e); }

Expected behaviour: "test.C" printed 3 times
Actual behaviour: and exception is thrown while in a format(i);


-- 

July 07, 2008
http://d.puremagic.com/issues/show_bug.cgi?id=2200





------- Comment #1 from 2korden@gmail.com  2008-07-07 15:00 -------
Currently writef/writefln fails with compile-time error deep inside std.format implementation with a "No property toString for test.I" error. It should be also updated to use cast to Object.

Or, if it is made by design, std.string.format should fail with the same reason at compile-time.


-- 

March 28, 2009
http://d.puremagic.com/issues/show_bug.cgi?id=2200


dsimcha@yahoo.com changed:

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




------- Comment #2 from dsimcha@yahoo.com  2009-03-27 19:43 -------


*** This bug has been marked as a duplicate of 535 ***


--