override

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

override

Nathan
Hi,

trying to use override to override a methods definition (strangely!) but
the compiler is choking on the overridden methods because the return
types differ. Am I missing something here? I thought that's why i was
overriding them..

Cheers,

Nathan

--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: override

MarcWeber
Excerpts from Nathan's message of Wed Aug 18 12:05:53 +0200 2010:
> Hi,
>
> trying to use override to override a methods definition (strangely!) but
> the compiler is choking on the overridden methods because the return
> types differ. Am I missing something here? I thought that's why i was
> overriding them..

Without source its hard to say. Try adding explicit return types to
*all* definitions of that function in your project.
Because HaXe tries to get the returntype from code there may be a third
definition in yet another class whose return type differs.

Marc Weber

--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: override

clemos
In reply to this post by Nathan
Hi

You can't change an overrided method's signature (param types and
return types), it would go against strict typing.
Overriding only allows to change the method's body.

As an alternative, you can either type your overrided method's return
value Dynamic or with a class/type which is common to both return
types.

+++++++
Clément

On Wed, Aug 18, 2010 at 12:05 PM, Nathan <[hidden email]> wrote:

> Hi,
>
> trying to use override to override a methods definition (strangely!) but the
> compiler is choking on the overridden methods because the return types
> differ. Am I missing something here? I thought that's why i was overriding
> them..
>
> Cheers,
>
> Nathan
>
> --
> haXe - an open source web programming language
> http://haxe.org
>

--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: override

Nathan
In reply to this post by MarcWeber
Marc Weber wrote:

> Excerpts from Nathan's message of Wed Aug 18 12:05:53 +0200 2010:
>> Hi,
>>
>> trying to use override to override a methods definition (strangely!) but
>> the compiler is choking on the overridden methods because the return
>> types differ. Am I missing something here? I thought that's why i was
>> overriding them..
>
> Without source its hard to say. Try adding explicit return types to
> *all* definitions of that function in your project.
> Because HaXe tries to get the returntype from code there may be a third
> definition in yet another class whose return type differs.

Cheers Mark, no luck though..

extern interface Foo {
   public var baz (default,never) : String;
}

extern interface Bar implements Foo {
   override public var baz (default,never) : Int;
}

gives:
  : Field baz is declared 'override' but doesn't override any field
  : Field baz has different type than in Foo
  : Int should be String

If I change to class rather than interface and use extends rather than
implement I get:
  : Field baz overload parent class with different or incomplete type
  : Int should be String

and similarly if I keep everything identical but specify
(default,default) in the extending class I get:
  : Field baz has different property access than in superclass

Thus, from what I can tell and in all tests, override doesn't appear to
do anything?

Cheers,

Nathan

--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: override

Nathan
In reply to this post by clemos
clemos wrote:
> Hi
>
> You can't change an overrided method's signature (param types and
> return types), it would go against strict typing.
> Overriding only allows to change the method's body.

gotcha - lol brain drain, that's right and expected functionality <doh>

> As an alternative, you can either type your overrided method's return
> value Dynamic or with a class/type which is common to both return
> types.

cheers Clément, that's the approach I've taken :)

> +++++++
> Clément
>
> On Wed, Aug 18, 2010 at 12:05 PM, Nathan <[hidden email]> wrote:
>> Hi,
>>
>> trying to use override to override a methods definition (strangely!) but the
>> compiler is choking on the overridden methods because the return types
>> differ. Am I missing something here? I thought that's why i was overriding
>> them..
>>
>> Cheers,
>>
>> Nathan
>>
>> --
>> haXe - an open source web programming language
>> http://haxe.org
>>
>
>


--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: override

MarcWeber
In reply to this post by Nathan
Hi Nathan

Sorry I don't know how to override properties.

All I know is that there have been some threads about how to override
Flash properties. Which is your target?

Maybe try searching the mailinglist for "overriding properties" or such.

My knowledge ends here.

Marc Weber

--
haXe - an open source web programming language
http://haxe.org