HeapsIO / hxbit

Haxe Binary serialization and network synchronization library
155 stars 30 forks source link

Doesn't work with haxe.ds.StringMap, haxe.ds.IntMap or abstracts of Map #5

Closed bendmorris closed 7 years ago

bendmorris commented 7 years ago

Given an abstract like this:

abstract Upgrades(Map<String, Int>) { ... }

I would expect it to be serializable since Map is supported. However, I see that in the macro getPropType skips over Map and goes straight to StringMap, "dereferencing" the abstract twice in one pass:

/home/ben/Dev/hxbit/hxbit/Macros.hx:201: TAbstract(catalyst.Upgrades,[])
/home/ben/Dev/hxbit/hxbit/Macros.hx:253: TInst(haxe.ds.StringMap,[TAbstract(Int,[])])

StringMap doesn't implement Serializable, so it is rejected.

I tried adding IntMap and StringMap in the TInst switch:

            case "haxe.ds.IntMap":
                var tk = getPropType(toType(macro : Int));
                var tv = getPropType(pl[0]);
                if( tv == null )
                    return null;
                PMap(tk, tv);
            case "haxe.ds.StringMap":
                var tk = getPropType(toType(macro : String));
                var tv = getPropType(pl[0]);
                if( tv == null )
                    return null;
                PMap(tk, tv);

but I may have done it incorrectly as this also fails with:

/home/ben/Dev/hxbit/hxbit/Macros.hx:458: characters 4-160 : Null<Map<String, Int>> should be Int
/home/ben/Dev/hxbit/hxbit/Macros.hx:458: characters 4-160 : Map<String, Int> should be Int