Using Dynamic objects as Map keys - haxe 3

915 views
Skip to first unread message

Samuel Batista

unread,
Mar 24, 2013, 3:03:09 AM3/24/13
to haxe...@googlegroups.com
Hey guys, I was using the ObjectHash<Array<Event>> class on my project, and I converted it to be a Map<Dynamic, Array<Event>>, I keep crashing when I try to see if an element exists in the map. This is the error I get:

ReferenceError: Error #1069: Property hashCode not found on GameClass and there is no default value.

Should I post a bug report somewhere? Is this Haxe 3 thing or NME thing?


Juraj Kirchheim

unread,
Mar 24, 2013, 7:39:44 AM3/24/13
to haxe...@googlegroups.com
You should be *very* careful with using `Map<Dynamic, T>` as that can
technically mean everything.

In you particular case, the compiler infers, that you want to use
HashMap, using this implicit conversion:
https://code.google.com/p/haxe/source/browse/trunk/std/Map.hx#134

The solution is to either use ObjectMap<T> or `Map<{}, T>`.

Regards,
Juraj

Samuel Batista

unread,
Mar 24, 2013, 5:07:21 PM3/24/13
to haxe...@googlegroups.com
That was an interesting suggestion, but unfortunately it gives me a compile error when I try to instantiate Map<{}, Array<_Events.EventHandler>>:

source/game/Events.hx:139: characters 18-52 : Type parameters of multi type abstracts must be known (for _Map.IMap<{ }, Array<_Events.EventHandler>>)

It's not a big deal since I can use Array<Array<_Events.EventHandler>> to implement the desired functionality.

Juraj Kirchheim

unread,
Mar 24, 2013, 5:10:51 PM3/24/13
to haxe...@googlegroups.com
And have you tried using haxe.ds.ObjectMap?
> --
> 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/groups/opt_out.
>
>

Samuel Batista

unread,
Mar 24, 2013, 5:34:27 PM3/24/13
to haxe...@googlegroups.com
I ended up using haxe.ds.ObjectMap, which works great. Thanks for the suggestion.

Tom

unread,
Apr 5, 2013, 5:08:58 AM4/5/13
to haxe...@googlegroups.com
Thanks! This saved my day. (Dynamic keys with Map, in Haxe3 dropped some error: hashCode is not a function, but with haxe.ds.ObjectMap everything is fine.)
Reply all
Reply to author
Forward
0 new messages