$lastSources is a reference (in the PHP sense – &value) so that adding further snaks to the previous source (with s123) works, which means that any time we assign to it, we must first break the reference using unset() (compare L1058 and L1103). This was missing in the beginning of the loop body, with the consequence that in a multi-line import, the last reference of each line except the last would be broken (it would have been reset to null by the next line).
Here’s what the bug looks like in action (note the missing sources for the date of death):
The commit is also available on GitHub: https://github.com/lucaswerkmeister/quickstatements/commit/d31e272e5bc3607584a87d7bc5d357ed8472c015
Improved “patch without arc”:
git checkout -b D1050 && curl -L https://github.com/lucaswerkmeister/quickstatements/commit/d31e272e5bc3607584a87d7bc5d357ed8472c015.patch | git am