One way to fix the issue:
function compute_prereqs(techs, recipe, history)
history = history or {}
local res = 0
for _, tech_name in pairs(techs) do
if not history[tech_name] then
history[tech_name] = 1
local tech = data.raw["technology"][tech_name]
for _, e in pairs(tech.effects or {}) do
if e.type == "change-recipe-productivity" and e.recipe == recipe then
unimplemented(tech.max_level ~= nil,
"Prequisite technology " .. tech.name .. " can be researched " .. tostring(tech.max_level) .. " times")
res = res + e.change end end
res = res + compute_prereqs(tech.prerequisites or {}, recipe, history) end
end
return res end
...