• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
Locked
0

AIR for iOS: bug in const initialization

Community Beginner ,
Nov 22, 2017 Nov 22, 2017

Copy link to clipboard

Copied

I've just run across a bug in AIR for iOS. `const` values that are declared inside a code block in a function that also has a local closure definition will not have their proper values.

The code:

public class Main extends Sprite {

    public function Main () {

        try {

            testConsts();

            trace("Everything works!");

            this.stage.color = 0x00ff00;

        } catch (e :Error) {

            trace("Something broke:\n" + e);

            this.stage.color = 0xff0000;

        }

    }

    public static function assertEquals (a :Number, b :Number, name :String) :void {

        if (a != b) {

            throw new Error(name + " assertion failed: " + a + " != " + b);

        }

    }

    public static function testConsts () :void {

        var closure :Function = function () :void {

            // I'm a closure that does nothing, but my existence breaks const initialization on iOS

        };

        var outerVar :Number = 1;

        const outerConst :Number = 2;

        assertEquals(outerVar, 1, "outerVar");

        assertEquals(outerConst, 2, "outerConst");

        if (outerVar == 1) {

            var innerVar :Number = 3;

            const innerConst :Number = 4;

            assertEquals(innerVar, 3, "innerVar");

            // on iOS, this fails. innerConst gets initialized to 0.

            // Removing the closure from the function makes things work as expected.

            assertEquals(innerConst, 4, "innerConst");

        }

    }

}

If this is run in an AIR desktop app or the Flash Player, everything behaves as it should and none of the assertions fail. However, on iOS, the final assertion will fail -- innerConst will have a value of 0 rather than 4.

If you remove the closure variable in the function, the assertion will pass. If you move innerConst's initialization out of its enclosing if-statement, the assertion will pass.

(I've made a GitHub repo demonstrating the bug here: https://github.com/tconkling/air_ios_consts_bug)

TOPICS
Performance issues

Views

276

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Employee ,
Nov 22, 2017 Nov 22, 2017

Copy link to clipboard

Copied

LATEST

Thanks for reporting this issue, we are investigating it.

Thanks,

Krati | Adobe AIR Engineering

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines