Looking through the code, there is this line (repeated a few times)
https://github.com/automerge/automerge/blob/08a456cc2ddc79d8c2f35953db0f1fd8ed418d0f/backend/encoding.js#L695
- We have
sum which is a number (defined above as let sum = 0.
sumShift can be undefined. This can be solved earlier in the code with const { count, sumValues, sumShift = 0 } = options;
firstValue is returned from decoder.readValue() that has way too many types: string, number, null, undefined, void
A little cleanup in the decoder reduces the return types to string | number | null filtering down to the line in question where firstValue can be of a number or string type.
anyString >>> anyNumber has a lot of side effects. It really just depends if the value can be cast to a number. If it can be cast, it will work as expected. If it can't it will return 0. Returning zero isn't probably correct as sum will not be incremented as a number would. Worse though, if sum += sumShift is falsey, then we end up with sum adding a string to 0. Now we aren't a number but 0some-text-string.
Am I wrong here? Or does the RLEEncoder basically incorrectly generate the sum of strings when using sumValues?
Looking through the code, there is this line (repeated a few times)
https://github.com/automerge/automerge/blob/08a456cc2ddc79d8c2f35953db0f1fd8ed418d0f/backend/encoding.js#L695
sumwhich is a number (defined above aslet sum = 0.sumShiftcan be undefined. This can be solved earlier in the code withconst { count, sumValues, sumShift = 0 } = options;firstValueis returned fromdecoder.readValue()that has way too many types: string, number, null, undefined, voidA little cleanup in the decoder reduces the return types to
string | number | nullfiltering down to the line in question wherefirstValuecan be of a number or string type.anyString >>> anyNumberhas a lot of side effects. It really just depends if the value can be cast to a number. If it can be cast, it will work as expected. If it can't it will return0. Returning zero isn't probably correct assumwill not be incremented as a number would. Worse though, ifsum += sumShiftis falsey, then we end up with sum adding a string to0. Now we aren't a number but0some-text-string.Am I wrong here? Or does the RLEEncoder basically incorrectly generate the
sumof strings when usingsumValues?