[Issue 2200] New: std.string.format behaves wrong when passing an interface reference

d-bugmail at puremagic.com d-bugmail at puremagic.com
Mon Jul 7 12:42:58 PDT 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 at digitalmars.com
        ReportedBy: 2korden at 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);


-- 



More information about the Digitalmars-d-bugs mailing list