Bug 2200 – std.string.format behaves wrong when passing an interface reference
Status
RESOLVED
Resolution
DUPLICATE
Severity
normal
Priority
P2
Component
phobos
Product
D
Version
D2
Platform
x86
OS
Windows
Creation time
2008-07-07T14:42:00Z
Last change time
2015-06-09T05:14:54Z
Assigned to
bugzilla
Creator
2korden
Comments
Comment #0 by 2korden — 2008-07-07T14:42:57Z
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);
Comment #1 by 2korden — 2008-07-07T15:00:22Z
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.
Comment #2 by dsimcha — 2009-03-27T19:43:52Z
*** This bug has been marked as a duplicate of 535 ***