Bug 3265 – .classinfo for Interface-typed reference does not return instance's ClassInfo
Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P4
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2009-08-25T07:40:00Z
Last change time
2015-06-09T01:28:05Z
Keywords
spec
Assigned to
nobody
Creator
hskwk
Comments
Comment #0 by hskwk — 2009-08-25T07:40:28Z
If function parameter type is a interface, parameter.classinfo returns inteface's ClassInfo instead of instance's ClassInfo.
interface I {}
class C : I {}
class D : C {}
void o(in Object obj) { writeln(obj.classinfo.name); }
void i(in I obj) { writeln(obj.classinfo.name); }
void c(in C obj) { writeln(obj.classinfo.name); }
void main()
{
auto d = new D;
o(d); // -> D
i(d); // -> I, wrong
c(d); // -> D
}
I suppose this behavior is a bug.
Comment #1 by hskwk — 2009-08-25T07:55:36Z
It is not related to function argument.
This bug occured by interface reference.
Sorry for rough information.
interface I {}
class C : I {}
class D : C {}
void main() {
auto d = new D;
C c = d;
writeln(c.classinfo.name);
I i = d;
writeln(i.classinfo.name);
Object o = d;
writeln(o.classinfo.name);
}
Comment #2 by hskwk — 2009-08-25T08:45:59Z
My friend noted that it is reasonable that interface.classinfo returns interface's classinfo for IUnknown or Interface to C++.
It sound true so that I changed the issue as not important.
I suggest that at least this spec should be documented.
This behavior is very confusing, I suppose it is better to replace classinfo property from interface reference by other appropriate way.
Comment #3 by github-bugzilla — 2012-01-23T01:25:45Z