Why does super class overriden method called?

121 views
Skip to first unread message

simo

unread,
Sep 22, 2013, 4:05:43 AM9/22/13
to haxe...@googlegroups.com

I am overriding a method ini in a super class, but strangely the ini method in super class is still called although I am not calling it using super

Any idea? is this a problem in haxe 3? it worked normally with haxe 2.1, p.s: its an OpenFL project, targeting flash ..

class superClass{

 public function new(){
  ..
  ini();
 }
 function ini():Void {
   // this line should not be reached, but, it is reached .. !
 }
}

class subClass extends superClass{
 override function ini():Void 
 {
   // I am not calling super ini here ..
 }
}

John Plsek

unread,
Sep 22, 2013, 5:15:57 AM9/22/13
to haxe...@googlegroups.com
You must be doing something odd/wrong in code you are not showing, because a minimal case works exactly as it should for me


--
To post to this group haxe...@googlegroups.com
http://groups.google.com/group/haxelang?hl=en
---
You received this message because you are subscribed to the Google Groups "Haxe" group.
For more options, visit https://groups.google.com/groups/opt_out.

Hugh

unread,
Sep 23, 2013, 12:21:58 AM9/23/13
to haxe...@googlegroups.com
Hi,
Do you get different behaviour is you add "public function new() { super(); }" to the subClass ?  If so, looks like a haxe+swf bug.  C++ can have problems calling virtual functions from a constructor, so the backend does some stuff to work around this.

Hugh

John Plsek

unread,
Sep 23, 2013, 1:21:43 AM9/23/13
to haxe...@googlegroups.com
One thing worth mentioning - the example code has lowercase first letter of class name - so, clearly the code shown, which wont even compile, has very little to do with the code that is having a run-time issue

sergey miryanov

unread,
Sep 23, 2013, 1:28:55 AM9/23/13
to haxe...@googlegroups.com
I already answered on SO and made test - and all work fine for me.

John Plsek

unread,
Sep 23, 2013, 2:25:31 AM9/23/13
to haxe...@googlegroups.com
but I answered here first, so I guess I win

Samir Sabri

unread,
Sep 23, 2013, 8:44:12 PM9/23/13
to haxe...@googlegroups.com
I have updated my SO question, I put my real code abstract, please check it http://stackoverflow.com/questions/18932039/why-does-super-class-overriden-method-called


You received this message because you are subscribed to a topic in the Google Groups "Haxe" group.

For more options, visit https://groups.google.com/groups/opt_out.



--
--
Kind Regards,
--------------------------------------------- 
Samir Sabri
Software Architect& Developer
Jordan-Middle East

sergey miryanov

unread,
Sep 23, 2013, 11:04:22 PM9/23/13
to haxe...@googlegroups.com

Please show how you create instances of your classes.

24.09.2013 6:44 пользователь "Samir Sabri" <as3...@gmail.com> написал:

Samir Sabri

unread,
Sep 24, 2013, 1:49:59 AM9/24/13
to haxe...@googlegroups.com
var wire:BeziereWire = new BeziereWire(board);
Its straight forward ..

John Plsek

unread,
Sep 24, 2013, 2:53:57 AM9/24/13
to haxe...@googlegroups.com
Once again, the "example code" wont even compile, so it's a bit difficult to see what you are actually doing wrong ... fixing up the code you posted, (a super() call in Component new function is all that is needed, and changing the parameter type to something that compiles in a MINIMAL test case)


here's a test case that actually COMPILES - hopefully you'll agree it is functionally identical to the non compiling code you posted on SO

import flash.display.Sprite;
import flash.Lib;

class EComponent extends Sprite
{
}

class Component extends EComponent
{

    public function new()
    {
        super();
        trace('Component new called');
        ini();
    }
    function ini():Void
    {
        trace('Component ini called');
    }

    function iniRotators():Void
    {
        trace('Component iniRotators called');
    }
}

class BeziereWire extends Component
{
    override function ini():Void
    {
        trace('BeziereWire ini called');
        iniRotators();     
    }
}

class Main
{
   
    static function main()
    {
        new BeziereWire();
    }
   
}


and here's the result of running it

Main.hx:16: Component new called
Main.hx:34: BeziereWire ini called
Main.hx:26: Component iniRotators called

As you can see Component ini called never gets called - which is the expected result

Regards

John

Samir Sabri

unread,
Sep 24, 2013, 4:15:36 AM9/24/13
to haxe...@googlegroups.com
Could it be a bug when targeting flash? what target did you use?

John Plsek

unread,
Sep 24, 2013, 5:30:50 AM9/24/13
to haxe...@googlegroups.com
I'll give you a clue

import flash.display.Sprite;
import flash.Lib;


You're still yet to  show any code that behaves the way you say it behaves - I'm guessing there is a fundamental error in the code you are not showing
Reply all
Reply to author
Forward
0 new messages