Thread overview
[Issue 309] New: std.boxer incorrectly handles interface instances (major problem in dmd reflection?)
Aug 24, 2006
d-bugmail
Sep 26, 2010
nfxjfg@gmail.com
August 24, 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@digitalmars.com
        ReportedBy: tbolsh@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.


-- 

September 26, 2010
http://d.puremagic.com/issues/show_bug.cgi?id=309


Andrei Alexandrescu <andrei@metalanguage.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
                 CC|                            |andrei@metalanguage.com
         Resolution|                            |WONTFIX


--- Comment #1 from Andrei Alexandrescu <andrei@metalanguage.com> 2010-09-25 17:53:40 PDT ---
std.boxer is on its way to deprecation.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
September 26, 2010
http://d.puremagic.com/issues/show_bug.cgi?id=309


nfxjfg@gmail.com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|RESOLVED                    |REOPENED
                 CC|                            |nfxjfg@gmail.com
         Resolution|WONTFIX                     |


--- Comment #2 from nfxjfg@gmail.com 2010-09-25 18:07:36 PDT ---
std.boxer is not deprecated in D1. Please don't close valid D1 bugs as WONTFIX.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
September 26, 2010
http://d.puremagic.com/issues/show_bug.cgi?id=309



--- Comment #3 from Andrei Alexandrescu <andrei@metalanguage.com> 2010-09-25 18:16:52 PDT ---
Apologies.

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