Jump to page: 1 25  
Page
Thread overview
typeid() broken for interfaces?
Nov 30, 2012
Gor Gyolchanyan
Nov 30, 2012
Maxim Fomin
Nov 30, 2012
Gor Gyolchanyan
Nov 30, 2012
Maxim Fomin
Dec 01, 2012
Walter Bright
Dec 02, 2012
Gor Gyolchanyan
Dec 02, 2012
pjmlp
Dec 03, 2012
Walter Bright
Dec 03, 2012
Gor Gyolchanyan
Dec 03, 2012
Walter Bright
Dec 03, 2012
Gor Gyolchanyan
Dec 03, 2012
Maxim Fomin
Dec 03, 2012
Walter Bright
Dec 02, 2012
deadalnix
Dec 02, 2012
Jonathan M Davis
Dec 03, 2012
Walter Bright
Dec 03, 2012
deadalnix
Dec 03, 2012
Paulo Pinto
Dec 03, 2012
Jacob Carlborg
Dec 03, 2012
Maxim Fomin
Dec 03, 2012
Jacob Carlborg
Dec 03, 2012
Jacob Carlborg
Dec 03, 2012
Walter Bright
Dec 03, 2012
deadalnix
Dec 03, 2012
Walter Bright
Dec 03, 2012
deadalnix
Dec 04, 2012
Maxim Fomin
Dec 04, 2012
Paulo Pinto
Dec 04, 2012
foobar
Dec 04, 2012
Jacob Carlborg
Dec 04, 2012
foobar
Dec 04, 2012
Jacob Carlborg
Dec 04, 2012
Maxim Fomin
Dec 04, 2012
deadalnix
Dec 04, 2012
Jacob Carlborg
Dec 04, 2012
Paulo Pinto
Dec 04, 2012
foobar
Dec 04, 2012
Paulo Pinto
Dec 04, 2012
foobar
Dec 04, 2012
Jonathan M Davis
Dec 05, 2012
foobar
Dec 05, 2012
Jonathan M Davis
Dec 06, 2012
foobar
Dec 06, 2012
Jonathan M Davis
Dec 06, 2012
deadalnix
Dec 05, 2012
foobar
Dec 05, 2012
foobar
November 30, 2012
interface I { }
class C: I { }

I object = new C;
assert(typeid(object) == typeid(C)); // fails

Is this normal or is it a bug?
Note, that the same works fine in case of a base class, rather then an
interface.

-- 
Bye,
Gor Gyolchanyan.


November 30, 2012
On Friday, 30 November 2012 at 10:05:21 UTC, Gor Gyolchanyan wrote:
> interface I { }
> class C: I { }
>
> I object = new C;
> assert(typeid(object) == typeid(C)); // fails
>
> Is this normal or is it a bug?
> Note, that the same works fine in case of a base class, rather then an
> interface.

It works according to spec. Object is expression of type interface I, so no dynamic type search is performed.
November 30, 2012
So the interfaces aren't supposed to hold a TypeInfo? That doesn't sound right. That makes interfaces useless in a very large set of use cases.


On Fri, Nov 30, 2012 at 2:55 PM, Maxim Fomin <maxim@maxim-fomin.ru> wrote:

> On Friday, 30 November 2012 at 10:05:21 UTC, Gor Gyolchanyan wrote:
>
>> interface I { }
>> class C: I { }
>>
>> I object = new C;
>> assert(typeid(object) == typeid(C)); // fails
>>
>> Is this normal or is it a bug?
>> Note, that the same works fine in case of a base class, rather then an
>> interface.
>>
>
> It works according to spec. Object is expression of type interface I, so no dynamic type search is performed.
>



-- 
Bye,
Gor Gyolchanyan.


November 30, 2012
On Friday, 30 November 2012 at 11:04:10 UTC, Gor Gyolchanyan wrote:
> So the interfaces aren't supposed to hold a TypeInfo? That doesn't sound
> right. That makes interfaces useless in a very large set of use cases.
>

You can find information about interfaces and classes at http://dlang.org/abi.html (interfaces have a pointer to vtbl[] which entries have pointers to TypeInfo). You can also write enhancement request if you consider your proposal worth implementing (but I don't understand what exactly you want).


December 01, 2012
On 11/30/2012 9:04 PM, Gor Gyolchanyan wrote:
> interface I { }
> class C: I { }
>
> I object = new C;
> assert(typeid(object) == typeid(C)); // fails
>
> Is this normal or is it a bug?

Normal, since the typeids of interfaces are not the same as for classes.

> Note, that the same works fine in case of a base class, rather then an
> interface.

That works, because classes are classes. Classes are not interfaces.



December 02, 2012
What's the logic in this behavior?


On Sun, Dec 2, 2012 at 1:28 AM, Walter Bright <newshound2@digitalmars.com>wrote:

> On 11/30/2012 9:04 PM, Gor Gyolchanyan wrote:
>
>> interface I { }
>> class C: I { }
>>
>> I object = new C;
>> assert(typeid(object) == typeid(C)); // fails
>>
>> Is this normal or is it a bug?
>>
>
> Normal, since the typeids of interfaces are not the same as for classes.
>
>
>  Note, that the same works fine in case of a base class, rather then an
>> interface.
>>
>
> That works, because classes are classes. Classes are not interfaces.
>
>
>
>


-- 
Bye,
Gor Gyolchanyan.


December 02, 2012
On Sunday, 2 December 2012 at 19:26:47 UTC, Gor Gyolchanyan wrote:
> What's the logic in this behavior?
>
>
> On Sun, Dec 2, 2012 at 1:28 AM, Walter Bright <newshound2@digitalmars.com>wrote:
>
>> On 11/30/2012 9:04 PM, Gor Gyolchanyan wrote:
>>
>>> interface I { }
>>> class C: I { }
>>>
>>> I object = new C;
>>> assert(typeid(object) == typeid(C)); // fails
>>>
>>> Is this normal or is it a bug?
>>>
>>
>> Normal, since the typeids of interfaces are not the same as for classes.
>>
>>
>>  Note, that the same works fine in case of a base class, rather then an
>>> interface.
>>>
>>
>> That works, because classes are classes. Classes are not interfaces.

Because interfaces don't extend object?
December 02, 2012
On Saturday, 1 December 2012 at 21:28:05 UTC, Walter Bright wrote:
> On 11/30/2012 9:04 PM, Gor Gyolchanyan wrote:
>> interface I { }
>> class C: I { }
>>
>> I object = new C;
>> assert(typeid(object) == typeid(C)); // fails
>>
>> Is this normal or is it a bug?
>
> Normal, since the typeids of interfaces are not the same as for classes.
>
>> Note, that the same works fine in case of a base class, rather then an
>> interface.
>
> That works, because classes are classes. Classes are not interfaces.

I'm still waiting to see an object that implement an interface but that isn't a class instance.
December 02, 2012
On Sunday, December 02, 2012 23:17:33 deadalnix wrote:
> I'm still waiting to see an object that implement an interface but that isn't a class instance.

Isn't that the case with the COM stuff? I remember there being something weird about them being interfaces but not classes, which is part of what has screwed over some of the interface-related stuff like opEquals.

- Jonathan M Davis
December 03, 2012
On 12/3/2012 6:26 AM, Gor Gyolchanyan wrote:
> What's the logic in this behavior?

Think of it this way. An int can be implicitly converted to a long, but they have different typeid's because they are different bits.

« First   ‹ Prev
1 2 3 4 5