Skip to content

Closure field assignment generates bad code #2

Description

@zeen

Assigning a closure to a class field generates code which doesn't compile. It fails in different ways depending on whether it's assigned from outside the class, or inside, and whether the field is static or non-static.

import objc.foundation.NSDictionary;
import ios.ui.UIApplicationMain;
import ios.ui.UIApplicationDelegate;
import ios.ui.UIResponder;
import ios.ui.UIApplication;
import ios.ui.UIWindow;

class MyClass {
    public var closure :String->Void;
    public function new() {}
}

class ClosureTest extends UIResponder implements UIApplicationDelegate {

    public static function test() {
        trace("Before");
        var x = new MyClass();
        x.closure = function(s) { trace(s); };
        x.closure("Closure!");
        trace("After");
    }

    public static function main() { return new UIApplicationMain ( ClosureTest ); }
    public static function unusedMain(){}
    public var window :UIWindow;
    public function application (application:UIApplication, didFinishLaunchingWithOptions:NSDictionary) :Bool {
        test();
        return true;
    }
    public function applicationDidBecomeActive (application:UIApplication) :Void {}
    public function applicationWillResignActive (application:UIApplication) :Void {}
}

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions