From 81fcde47fefc36a8871de734f56eb94a66d499f0 Mon Sep 17 00:00:00 2001 From: Dave Lucia Date: Wed, 18 Feb 2026 09:59:34 -0500 Subject: [PATCH] fix: test for loops with external variables Closes #147 --- test/lua_test.exs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/test/lua_test.exs b/test/lua_test.exs index 37682a7..40640a0 100644 --- a/test/lua_test.exs +++ b/test/lua_test.exs @@ -1962,6 +1962,20 @@ defmodule LuaTest do assert {[true], _} = Lua.eval!(lua, code) end + test "loops with external variables", %{lua: lua} do + code = ~S""" + function run(n) + for i = 1, n do + local obj = {} -- overwrites limit register → infinite loop + end + return n + end + return run(3) + """ + + assert {[3], _} = Lua.eval!(lua, code) + end + @tag :skip test "closure upvalue mutation through nested scope", %{lua: lua} do # Known limitation: upvalue mutation through nested function scopes