self referencing anonymous function?

51 views
Skip to first unread message

George Kurelic

unread,
Apr 8, 2017, 12:57:48 AM4/8/17
to Haxe
This works in flash/html5, but throws an exception in neko
    var func:Void->Void;
    func
= function():Void { trace(func); };// Uncaught exception - Invalid array access
    trace
(func); //#function:1
    func
();


If you're wondering why anyone would do this, it's for this. the ability to add a listener that automatically removes itself.
I don't know how to see the code it's compiled to, but I'm confused by "invalid array access" of all errors.

additionally, Neko doesn't seem to like this, either, I get Uncaught exception - Invalid field access: __s
Is there any reason that this wouldn't be treated as a normal StringMap<AssertLogger>?

Juraj Kirchheim

unread,
Apr 8, 2017, 5:03:41 AM4/8/17
to haxe...@googlegroups.com
Why should the function be anonymous to start with? Try just a named local function: http://try.haxe.org/#00c5B

That said, the particular error you're getting seems like a bug to me. I can't think of a reason why the code should not work.

As for the second error, the problem is that `null` is not a valid key in StringMaps on neko. See http://api.haxe.org/Map.html#get :

> If key is null, the result is unspecified.

In short, you should not rely on unspecified behavior ;)

Best,
Juraj

--
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/d/optout.

George Kurelic

unread,
Apr 8, 2017, 6:03:24 PM4/8/17
to Haxe
Both of those worked, thanks! I forgot about local named funcs, as I never really use them
Reply all
Reply to author
Forward
0 new messages