Bug 309 – std.boxer incorrectly handles interface instances (major problem in dmd reflection?)
Status
RESOLVED
Resolution
WONTFIX
Severity
normal
Priority
P2
Component
phobos
Product
D
Version
D1 (retired)
Platform
x86
OS
All
Creation time
2006-08-24T10:40:00Z
Last change time
2013-11-15T19:05:03Z
Assigned to
nobody
Creator
tbolsh
Comments
Comment #0 by tbolsh — 2006-08-24T10:40:49Z
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 by andrei — 2010-09-25T17:53:40Z
std.boxer is on its way to deprecation.
Comment #2 by nfxjfg — 2010-09-25T18:07:36Z
std.boxer is not deprecated in D1. Please don't close valid D1 bugs as WONTFIX.