Skip to content

Commit

Permalink
minor refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
hishamhm committed Jan 6, 2025
1 parent 44c13b0 commit 0be55c8
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
7 changes: 4 additions & 3 deletions tl.lua
Original file line number Diff line number Diff line change
Expand Up @@ -13102,10 +13102,11 @@ self:expand_type(node, values, elements) })
end

do
local function add_interface_fields(self, what, fields, field_order, resolved, named, list)
local function add_interface_fields(self, fields, field_order, resolved, named, list)
for fname, ftype in fields_of(resolved, list) do
if fields[fname] then
if not self:is_a(fields[fname], ftype) then
local what = list == "meta" and "metamethod" or "field"
self.errs:add(fields[fname], what .. " '" .. fname .. "' does not match definition in interface %s", named)
end
else
Expand Down Expand Up @@ -13152,11 +13153,11 @@ self:expand_type(node, values, elements) })
if iface.typename == "nominal" then
local ri = self:resolve_nominal(iface)
assert(ri.typename == "interface")
add_interface_fields(self, "field", t.fields, t.field_order, ri, iface)
add_interface_fields(self, t.fields, t.field_order, ri, iface)
if ri.meta_fields then
t.meta_fields = t.meta_fields or {}
t.meta_field_order = t.meta_field_order or {}
add_interface_fields(self, "metamethod", t.meta_fields, t.meta_field_order, ri, iface, "meta")
add_interface_fields(self, t.meta_fields, t.meta_field_order, ri, iface, "meta")
end
else
if not t.elements then
Expand Down
7 changes: 4 additions & 3 deletions tl.tl
Original file line number Diff line number Diff line change
Expand Up @@ -13102,10 +13102,11 @@ do
end

do
local function add_interface_fields(self: TypeChecker, what: string, fields: {string:Type}, field_order: {string}, resolved: RecordLikeType, named: NominalType, list?: MetaMode)
local function add_interface_fields(self: TypeChecker, fields: {string:Type}, field_order: {string}, resolved: RecordLikeType, named: NominalType, list?: MetaMode)
for fname, ftype in fields_of(resolved, list) do
if fields[fname] then
if not self:is_a(fields[fname], ftype) then
local what = list == "meta" and "metamethod" or "field"
self.errs:add(fields[fname], what .." '" .. fname .. "' does not match definition in interface %s", named)
end
else
Expand Down Expand Up @@ -13152,11 +13153,11 @@ do
if iface is NominalType then
local ri = self:resolve_nominal(iface)
assert(ri is InterfaceType)
add_interface_fields(self, "field", t.fields, t.field_order, ri, iface)
add_interface_fields(self, t.fields, t.field_order, ri, iface)
if ri.meta_fields then
t.meta_fields = t.meta_fields or {}
t.meta_field_order = t.meta_field_order or {}
add_interface_fields(self, "metamethod", t.meta_fields, t.meta_field_order, ri, iface, "meta")
add_interface_fields(self, t.meta_fields, t.meta_field_order, ri, iface, "meta")
end
else
if not t.elements then
Expand Down

0 comments on commit 0be55c8

Please sign in to comment.