haxetink / tink_pure

Pure immutable data.
MIT License
10 stars 7 forks source link

List iterator crashes if List was improperly constructed #11

Closed serjek closed 5 years ago

serjek commented 5 years ago

Let's say we have incoming data where we expect List and that is parsed like this:

function transform(data:Test) {
    trace(data);
    trace(data.l);
    trace(data.l.iterator());
    for (m in data.l) trace(m);
}
var incoming = haxe.Json.parse('{"l":""}');
transform(incoming);

...
typedef Test = {
    var l(default, never):tink.pure.List<String>;
}

Following will output: src/MainClient.hx:7: { l: '' } src/MainClient.hx:8: src/MainClient.hx:9: { list: [ '' ] } and then crash: TypeError: Cannot read property 'length' of undefined at tink_pure_NodeIterator.next

back2dos commented 5 years ago

There's nothing we can do here, because the code is totally subverting the type system. It's not even specific to tink_pure: using a plain Iterable, it will crash the same way.

You could always use tink_json ;)