Skip to content

Commit

Permalink
total: do not consider a record function to be a missing field
Browse files Browse the repository at this point in the history
Fixes #747.
  • Loading branch information
hishamhm committed Jun 1, 2024
1 parent c4dfe37 commit d8ad610
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 2 deletions.
12 changes: 12 additions & 0 deletions spec/declaration/local_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -412,6 +412,18 @@ describe("local", function()
likes = {name='orange'}
}
]]))

it("does not consider a record function to be a missing field", util.check([[
local record A
v: number
end
function A:echo()
print('A:', self.v)
end
local b <total>: A = { v = 10 }
]]))
end)

describe("<close>", function()
Expand Down
4 changes: 3 additions & 1 deletion tl.lua
Original file line number Diff line number Diff line change
Expand Up @@ -1889,6 +1889,7 @@ end






local TruthyFact = {}
Expand Down Expand Up @@ -10473,7 +10474,7 @@ self:expand_type(node, values, elements) })
local missing
for _, key in ipairs(t.field_order) do
local ftype = t.fields[key]
if not (ftype.typename == "typedecl" or ftype.typename == "typealias") then
if not (ftype.typename == "typedecl" or ftype.typename == "typealias" or (ftype.typename == "function" and ftype.is_record_function)) then
is_total, missing = total_check_key(key, seen_keys, is_total, missing)
end
end
Expand Down Expand Up @@ -11357,6 +11358,7 @@ self:expand_type(node, values, elements) })
typeargs = node.typeargs,
args = args,
rets = self.get_rets(rets),
is_record_function = true,
}))

local open_t, open_v, owner_name = self:find_record_to_extend(node.fn_owner)
Expand Down
4 changes: 3 additions & 1 deletion tl.tl
Original file line number Diff line number Diff line change
Expand Up @@ -1781,6 +1781,7 @@ local record FunctionType
where self.typename == "function"

is_method: boolean
is_record_function: boolean
min_arity: integer
args: TupleType
rets: TupleType
Expand Down Expand Up @@ -10473,7 +10474,7 @@ do
local missing: {string}
for _, key in ipairs(t.field_order) do
local ftype = t.fields[key]
if not (ftype is TypeDeclType or ftype is TypeAliasType) then
if not (ftype is TypeDeclType or ftype is TypeAliasType or (ftype is FunctionType and ftype.is_record_function)) then
is_total, missing = total_check_key(key, seen_keys, is_total, missing)
end
end
Expand Down Expand Up @@ -11357,6 +11358,7 @@ do
typeargs = node.typeargs,
args = args,
rets = self.get_rets(rets),
is_record_function = true,
}))

local open_t, open_v, owner_name = self:find_record_to_extend(node.fn_owner)
Expand Down

0 comments on commit d8ad610

Please sign in to comment.