diff --git a/spec/declaration/local_spec.lua b/spec/declaration/local_spec.lua index ea3819081..a1ae1b45a 100644 --- a/spec/declaration/local_spec.lua +++ b/spec/declaration/local_spec.lua @@ -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 : A = { v = 10 } + ]])) end) describe("", function() diff --git a/tl.lua b/tl.lua index a787ac85f..eed8fa9a3 100644 --- a/tl.lua +++ b/tl.lua @@ -1889,6 +1889,7 @@ end + local TruthyFact = {} @@ -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 @@ -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) diff --git a/tl.tl b/tl.tl index caa18e084..73da52a6d 100644 --- a/tl.tl +++ b/tl.tl @@ -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 @@ -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 @@ -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)