D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 309 - std.boxer incorrectly handles interface instances (major problem in dmd reflection?)
Summary: std.boxer incorrectly handles interface instances (major problem in dmd refle...
Status: RESOLVED WONTFIX
Alias: None
Product: D
Classification: Unclassified
Component: phobos (show other issues)
Version: D1 (retired)
Hardware: x86 All
: P2 normal
Assignee: No Owner
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2006-08-24 10:40 UTC by Timofei Bolshakov
Modified: 2013-11-15 19:05 UTC (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Timofei Bolshakov 2006-08-24 10:40:49 UTC
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.
Comment 1 Andrei Alexandrescu 2010-09-25 17:53:40 UTC
std.boxer is on its way to deprecation.
Comment 2 nfxjfg 2010-09-25 18:07:36 UTC
std.boxer is not deprecated in D1. Please don't close valid D1 bugs as WONTFIX.
Comment 3 Andrei Alexandrescu 2010-09-25 18:16:52 UTC
Apologies.
Comment 4 Andrei Alexandrescu 2013-11-15 19:05:03 UTC
D1 is not supported anymore.