#2061 JS: Constructor chain and private method call

bedla Thu 15 Nov 2012

Hi, I have following problem with calling private method inside constructor chain:

I have two class in hiearchy with both have setupProperties private method.

@Js
class Animal
{
    new make()
    {
        echo("Animal.make() $this.hash")
        setupProperties
    }

    private Void setupProperties()
    {
        echo("Animal.setupProperties() $this.hash")
    }

}
@Js
class Lion : Animal
{
    new make() : super()
    {
        echo("Lion.make() $this.hash")

        setupProperties
    }

    private Void setupProperties()
    {
        echo("Lion.setupProperties() $this.hash")
    }
}

I have following test case class:

@Js
class TestConstructorChainJs : Test
{
    Void testIt()
    {

        a := Animal()
        echo("--------------")
        b := Lion()

    }
}

When running generated bytecode everything is OK:

~/IdeaProjects/fantom-test % fant fantomtest

-- Run:  fantomtest::TestConstructorChainJs.testIt...
Animal.make() 1601025338
Animal.setupProperties() 1601025338
--------------
Animal.make() 1236688438
Animal.setupProperties() 1236688438
Lion.make() 1236688438
Lion.setupProperties() 1236688438
   Pass: fantomtest::TestConstructorChainJs.testIt [0]

Time: 28ms

***
*** All tests passed! [1 tests, 1 methods, 0 verifies]
***

But when running generated JS wrong setupProperties method is called:

~/IdeaProjects/fantom-test % fan compilerJs::TestRunner fantomtest

-- Run: fantomtest::TestConstructorChainJs.testIt...
Animal.make() -9007199254740992
Animal.setupProperties() -9007199254740992
--------------
Animal.make() -9007199254740991
Lion.setupProperties() -9007199254740991
Lion.make() -9007199254740991
Lion.setupProperties() -9007199254740991
   Pass: fantomtest::TestConstructorChainJs.testIt  [0]

Time: 65ms

***
*** All tests passed! [1 tests, 1 methods, 0 verifies]
***

Yuri Strot Thu 15 Nov 2012

Looks like this is old but known issue: #1651

andy Thu 15 Nov 2012

Yes this is a known issue - we should at least update compilerJs in the meantime to warn for those cases. I thought I had done that - but I guess not - will take a look.

bedla Thu 15 Nov 2012

Ok, I will try to live with that ;-)

Login or Signup to reply.