Skip to content

Commit

Permalink
interfaces: fix collect_interfaces
Browse files Browse the repository at this point in the history
  • Loading branch information
hishamhm committed Jun 1, 2024
1 parent 3e00e60 commit c4dfe37
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 18 deletions.
18 changes: 18 additions & 0 deletions spec/subtyping/interface_spec.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
local util = require("spec.util")

describe("subtyping of interfaces:", function()
it("record inherits interface array definition", util.check([[
local interface MyInterface
is {MyInterface}
x: integer
end
local record MyRecord
is MyInterface
end
local r: MyRecord = {}
print(#r)
]]))
end)

16 changes: 7 additions & 9 deletions tl.lua
Original file line number Diff line number Diff line change
Expand Up @@ -12001,16 +12001,14 @@ self:expand_type(node, values, elements) })
for _, iface in ipairs(t.interface_list) do
if iface.typename == "nominal" then
local ri = self:resolve_nominal(iface)
if not (ri.typename == "invalid") then
if ri.typename == "interface" then
if not ri.interfaces_expanded and not seen[ri] then
seen[ri] = true
collect_interfaces(self, list, ri, seen)
end
table.insert(list, iface)
else
self.errs:add(iface, "attempted to use %s as interface, but its type is %s", iface, ri)
if ri.typename == "interface" then
if ri.interfaces_expanded and not seen[ri] then
seen[ri] = true
collect_interfaces(self, list, ri, seen)
end
table.insert(list, iface)
else
self.errs:add(iface, "attempted to use %s as interface, but its type is %s", iface, ri)
end
else
if not seen[iface] then
Expand Down
16 changes: 7 additions & 9 deletions tl.tl
Original file line number Diff line number Diff line change
Expand Up @@ -12001,16 +12001,14 @@ do
for _, iface in ipairs(t.interface_list) do
if iface is NominalType then
local ri = self:resolve_nominal(iface)
if not (ri.typename == "invalid") then
if ri is InterfaceType then
if not ri.interfaces_expanded and not seen[ri] then
seen[ri] = true
collect_interfaces(self, list, ri, seen)
end
table.insert(list, iface)
else
self.errs:add(iface, "attempted to use %s as interface, but its type is %s", iface, ri)
if ri is InterfaceType then
if ri.interfaces_expanded and not seen[ri] then
seen[ri] = true
collect_interfaces(self, list, ri, seen)
end
table.insert(list, iface)
else
self.errs:add(iface, "attempted to use %s as interface, but its type is %s", iface, ri)
end
else
if not seen[iface] then
Expand Down

0 comments on commit c4dfe37

Please sign in to comment.