3265 – .classinfo for Interface-typed reference does not return instance's ClassInfo

D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 3265 - .classinfo for Interface-typed reference does not return instance's ClassInfo
Summary: .classinfo for Interface-typed reference does not return instance's ClassInfo
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: All All
: P4 normal
Assignee: No Owner
URL:
Keywords: spec
Depends on:
Blocks:
Reported: 2009年08月25日 07:40 UTC by HOSOKAWA Kenchi
Modified: 2015年06月09日 01:28 UTC (History)
1 user (show)

See Also:


Attachments
Add an attachment (proposed patch, testcase, etc.)

Note You need to log in before you can comment on or make changes to this issue.
Description HOSOKAWA Kenchi 2009年08月25日 07:40:28 UTC
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 HOSOKAWA Kenchi 2009年08月25日 07:55:36 UTC
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 HOSOKAWA Kenchi 2009年08月25日 08:45:59 UTC
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 github-bugzilla 2012年01月23日 01:25:45 UTC
Commit pushed to https://github.com/D-Programming-Language/d-programming-language.org
https://github.com/D-Programming-Language/d-programming-language.org/commit/226de8cfbb07d25c498b5e2b7b794a65437b9ebc
fix Issue 3265 - .classinfo for Interface-typed reference does not return instance's ClassInfo


AltStyle によって変換されたページ (->オリジナル) /