Closed ofrzeta closed 10 years ago
Functions are not values; so this behavior is totally correct.
Ah, I think that the issue was actually fixed when we added the missing constraint {} on ObjectMap, I was surprised that it was allowed to create Map with functions as keys.
There is a FunctionMap implementation in tinkerbell if you really need it: https://github.com/back2dos/tinkerbell/blob/master/src/tink/collections/maps/FunctionMap.hx
I don't see how that constraint works - at least when I am using a Dynamic type. When I compile the following the code, it get an exception
import haxe.ds.ObjectMap;
class Test {
static function myfunc(param: Int) {
}
static function main() {
var targetLibraries:ObjectMap <Dynamic, Int> = new ObjectMap<Dynamic, Int> ();
targetLibraries.set (myfunc, 1);
trace(targetLibraries);
}
}
ObjectMap is only supposed to contain objects, and functions are not objects in Haxe. In your example this goes unoticed because you're using Dynamic, which is unsafe. Use {}
(the empty object which works with all objects) and you'll see the error displayed.
functions as keys are not possible with the ObjectMap implementation (in Neko?) because the getID() calls fail.