Bug or Feature?

Max Samuha maxter at i.com.ua_spamless
Wed Jun 14 12:55:31 PDT 2006


On Wed, 14 Jun 2006 15:07:20 +0000 (UTC), leoandru
<leoandru_member at pathlink.com> wrote:

>In article <3gav82l5bdkt0logigc3vokptkk35nrkvn at 4ax.com>, Max Samuha says...
>>
>>On Tue, 13 Jun 2006 21:56:40 +0000 (UTC), leoandru
>><leoandru_member at pathlink.com> wrote:
>>
>>><code>
>>>interface Foo
>>>{
>>>Object clone();
>>>}
>>>
>>>class Bar : Foo
>>>{
>>>Bar clone()
>>>{
>>>return this; 
>>>}
>>>
>>>}
>>>
>>>void main()
>>>{
>>>Bar b = new Bar();
>>>Bar c = b.clone(); //works fine
>>>
>>>Foo f = b;
>>>Foo g = f.clone(); //access violation
>>
>>Threre should be a cast to Foo: Foo g = cast(Foo)f.clone(). The code
>>works well for me (WinXP, D 0.160). 
>>
>>>}
>>></code>
>>
>>Do you get access violation or AssertError? If it's AssertError, you
>>might forget to put 'return' in a function that requirs a value to be
>>returned (int main(...){return 0;}?). D doesn't warn about missing
>>returns at compile time.
>>
>
>
>Yeah I had a return in the affected code in that example I returned a reference
>to the object itself. gessh! didn't know I had to cast ok thanks! I'll try that
>then.
>

Sorry, I didn't notice that Bar implements Object clone() as Bar
clone(). The return types of the interface method and the method's
implementation differ. This seems to be illigal (At least, this is
illegal in C#). Anybody knows, why this compiles and works?



More information about the Digitalmars-d mailing list