Skip to content

Commit

Permalink
fix stack overflow when nested interface extends its parent
Browse files Browse the repository at this point in the history
Fixes #860.
  • Loading branch information
hishamhm committed Jan 10, 2025
1 parent f5bb25b commit 80c7c35
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 25 deletions.
9 changes: 9 additions & 0 deletions spec/lang/declaration/record_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -1072,3 +1072,12 @@ describe("abstract check", function()
{ y = 2, x = 10, msg = "interfaces cannot contain record definitions", }
}))
end)

describe("loop check", function()
it("nested interfaces extending outer interface", util.check([[
local interface X
interface A is X
end
end
]]))
end)
27 changes: 15 additions & 12 deletions tl.lua
Original file line number Diff line number Diff line change
Expand Up @@ -8083,12 +8083,15 @@ do
end

local function close_nested_records(t)
for _, ft in pairs(t.fields) do
if ft.typename == "typedecl" then
ft.closed = true
local def = ft.def
if def.fields then
close_nested_records(def)
if t.closed then
return
end
local tdef = t.def
if tdef.fields then
t.closed = true
for _, ft in pairs(tdef.fields) do
if ft.typename == "typedecl" then
close_nested_records(ft)
end
end
end
Expand All @@ -8098,11 +8101,7 @@ do
for _, var in pairs(scope.vars) do
local t = var.t
if t.typename == "typedecl" then
t.closed = true
local def = t.def
if def.fields then
close_nested_records(def)
end
close_nested_records(t)
end
end
end
Expand Down Expand Up @@ -13216,7 +13215,11 @@ self:expand_type(node, values, elements) })
end
else
table.insert(field_order, fname)
fields[fname] = resolve_self(self, ftype)
if ftype.typename == "typedecl" then
fields[fname] = ftype
else
fields[fname] = resolve_self(self, ftype)
end
end
end
end
Expand Down
29 changes: 16 additions & 13 deletions tl.tl
Original file line number Diff line number Diff line change
Expand Up @@ -8082,13 +8082,16 @@ do
end
end

local function close_nested_records(t: RecordLikeType)
for _, ft in pairs(t.fields) do
if ft is TypeDeclType then
ft.closed = true
local def = ft.def
if def is RecordLikeType then
close_nested_records(def)
local function close_nested_records(t: TypeDeclType)
if t.closed then
return
end
local tdef = t.def
if tdef is RecordLikeType then
t.closed = true
for _, ft in pairs(tdef.fields) do
if ft is TypeDeclType then
close_nested_records(ft)
end
end
end
Expand All @@ -8098,11 +8101,7 @@ do
for _, var in pairs(scope.vars) do
local t = var.t
if t is TypeDeclType then
t.closed = true
local def = t.def
if def is RecordLikeType then
close_nested_records(def)
end
close_nested_records(t)
end
end
end
Expand Down Expand Up @@ -13216,7 +13215,11 @@ do
end
else
table.insert(field_order, fname)
fields[fname] = resolve_self(self, ftype)
if ftype is TypeDeclType then
fields[fname] = ftype
else
fields[fname] = resolve_self(self, ftype)
end
end
end
end
Expand Down

0 comments on commit 80c7c35

Please sign in to comment.