haxetink / tink_json

Macro powered JSON.
The Unlicense
34 stars 9 forks source link

UInt support on JS #58

Closed Gama11 closed 4 years ago

Gama11 commented 5 years ago

UInt is currently not serialized correctly on all targets / has inconsistent results across targets.

class Main {
    static function main() {
        var i:UInt = 0x80000000;
        trace(i); // 2147483648
        trace((i : Int)); // -2147483648

        var data:Data = {i: i};
        trace(tink.Json.stringify(data));
    }
}

typedef Data = {
    var i:UInt;
}

Not sure if there's more targets with incorrect results.

kevinresol commented 5 years ago

I am not sure how to reliably parse string into a "Haxe UInt"

public function parseUInt(v:String) {
    var ret:UInt = 0;
    for(i in 0...v.length) ret += Std.parseInt(v.charAt(i)) * Std.int(Math.pow(10, v.length - i - 1));
    return ret;
}

var u = parseUInt('2147483648'); // gives a native int of value 2147483648 on python
trace(u == 0x80000000); // false, because the latter is generated as -2147483648

Not sure what to expect here...

kevinresol commented 5 years ago

Keeping open for the python mystery

back2dos commented 4 years ago

Reported in https://github.com/HaxeFoundation/haxe/issues/9354