Closed
Description
This
let printLength = (json: JSON.t) =>
switch json {
| Object(o) => Console.log2("Length: ", o->Dict.valuesToArray->Array.length)
| _ => ()
}
compiles to
function printLength(json) {
if (typeof json !== "object" || Array.isArray(json)) {
return;
}
console.log("Length: ", Object.values(json).length);
}
which is incorrect because a check for null
is missing.
It will crash at runtime if passed a null
value.