Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extending a class with an optional param in constructor creates errors #190

Open
peteshand opened this issue Sep 21, 2013 · 0 comments
Open

Comments

@peteshand
Copy link

package test 
{
    public class SuperTestBase 
    {
        public function SuperTestBase(v:Boolean=false) 
        {

        }
    }
}
package test 
{
    public class SuperTest extends SuperTestBase
    {
        public function SuperTest() 
        {
            super();
        }
    }
}

The above actionscript creates the following SuperTest javascript:

if (typeof test == "undefined")
    var test = {};

test.SuperTest = function() {
    test.SuperTestBase.call(thisfalse);
};

$inherit(test.SuperTest, test.SuperTestBase);

test.SuperTest.className = "test.SuperTest";

test.SuperTest.getRuntimeDependencies = function(t) {
    var p;
    return [];
};

test.SuperTest.getStaticDependencies = function(t) {
    var p;
    return [];
};

test.SuperTest.injectionPoints = function(t) {
    var p;
    switch (t) {
        case 1:
            p = test.SuperTestBase.injectionPoints(t);
            break;
        case 2:
            p = test.SuperTestBase.injectionPoints(t);
            break;
        case 3:
            p = test.SuperTestBase.injectionPoints(t);
            break;
        default:
            p = [];
            break;
    }
    return p;
};

Line 5 should read:

test.SuperTestBase.call();

or at very least:

test.SuperTestBase.call(false);

however it currently compiles to

test.SuperTestBase.call(thisfalse);

work around is to manually set the Boolean in AS when calling super.

        public function SuperTest()
        {
            super(false);
        }

However this particular configuration appears to be creating other issues as well. For example if you create a new empty vector

package test
{
    public class SuperTest extends SuperTestBase
    {
        public var _vec:Vector.<Object> = new Vector.<Object>();

        public function SuperTest()
        {
            super(false);
        }
    }
}

you get the following VectorTest javascript

if (typeof test == "undefined")
    var test = {};

test.SuperTest = function() {
    this._vec = [false];
    test.SuperTestBase.call(this, false);
};

$inherit(test.SuperTest, test.SuperTestBase);

test.SuperTest.className = "test.SuperTest";

test.SuperTest.getRuntimeDependencies = function(t) {
    var p;
    return [];
};

test.SuperTest.getStaticDependencies = function(t) {
    var p;
    return [];
};

test.SuperTest.injectionPoints = function(t) {
    var p;
    switch (t) {
        case 1:
            p = test.SuperTestBase.injectionPoints(t);
            break;
        case 2:
            p = test.SuperTestBase.injectionPoints(t);
            break;
        case 3:
            p = test.SuperTestBase.injectionPoints(t);
            break;
        default:
            p = [];
            break;
    }
    return p;
};

On line 5 you would expect to get

this._vec = [];

however it current compiles to

this._vec = [false];

if you change the Boolean in the base class to have no default value

public function SuperTestBase(v:Boolean)
{

}

then the vector initialises correctly

workaround: don't use default param values in constructor... which isn't really much of a workaround seeing as how common it is to use default param values in the constructor :/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant