[Issue 309] New: std.boxer incorrectly handles interface instances (major problem in dmd reflection?)

d-bugmail at puremagic.com d-bugmail at puremagic.com
Thu Aug 24 08:40:55 PDT 2006


http://d.puremagic.com/issues/show_bug.cgi?id=309

           Summary: std.boxer incorrectly handles interface instances (major
                    problem in dmd reflection?)
           Product: D
           Version: 0.163
          Platform: PC
        OS/Version: Linux
            Status: NEW
          Severity: normal
          Priority: P2
         Component: Phobos
        AssignedTo: bugzilla at digitalmars.com
        ReportedBy: tbolsh at gmail.com


I define interface A and implement it in class B.
After that I have to variables : A a and B b.
Both of them got instanciated with implementation class B.
After that I box both of this variables and found out that
variable b cannot be unboxed as A! Here is the code:

import std.boxer;
import std.stdio;

interface A {
    public char[] message();
}
class B : A {
    char []info; 
    this(char []info){ this.info = info; }
    public char[] toString(){ return info; }
    public char[] message(){  return toString(); }
}

void main(char [][]args){
    A aa = new B( "I am A" );
    B bb = new B( "I am A too!");
    Box a = box( aa ), b = box( bb );

    if( unboxable!(A)( a ) ) writefln( "a is A!" );
    else                     writefln( "a is not A!" );

    if( unboxable!(A)( b ) ) writefln( "b is A! It says: "~b.toString() );
    else                     writefln( "b is not A! Despite it says:
"~b.toString() );
}

Here is command lines and output:
> dmd -I/usr/local/dmd/src/phobos TestBoxError.d std/boxer.d
gcc TestBoxError.o boxer.o -o TestBoxError -m32 -lphobos -lpthread -lm 
Process dmd exited with code 0
> ./TestBoxError
a is A!
b is not A! Despite it says: I am A too!

I suspect that interface information may be not correctly processed in
std.boxer

If A is a class everything is fine.

So, it also may be dmd bugs in keeping interface implementation information.

It is not extremly severe - there are simple workaround, but it prevent from
designing good reusable libraries with boxing.

Workaround (kind-of): create abstract class that implements that interface, but 
does nothing. Use this absract class for all your classes instead of
implementing interface. Keep interface in documenation hoping that this bug
will be fixed.


-- 




More information about the Digitalmars-d-bugs mailing list