That's.. odd. Are you sure you're on the most recent version? Line 361 of func.lua is an empty spacer line in the latest v9.3.7
Theoretically, the function does call itself infinitely, potentially causing a stack overflow, but that depends entirely on if each subsequent entity has a next_upgrade target, which should eventually end, like even 5dims only has 10 tiers, the most I've seen. To cause an error like that would require a chain of assemblers or furnaces or something to have an absurd number of next_upgrade targets, which makes me think it must be affected by another mod?
Or possibly, if another mod somehow made a loop of next_upgrade targets, like A upgrades to B upgrades to C which "upgrades" back to A? That would be weird... but maybe not impossible?