Skip to content

Commit

Permalink
forbid records inside interfaces
Browse files Browse the repository at this point in the history
Fixes #870.
  • Loading branch information
hishamhm committed Jan 10, 2025
1 parent 78c7fbb commit f5bb25b
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 2 deletions.
10 changes: 10 additions & 0 deletions spec/lang/declaration/record_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -1061,4 +1061,14 @@ describe("abstract check", function()
]], {
{ y = 7, x = 9, msg = "interfaces are abstract", }
}))

it("for record definitions inside interfaces", util.check_syntax_error([[
local interface X
record Y
z: number
end
end
]], {
{ y = 2, x = 10, msg = "interfaces cannot contain record definitions", }
}))
end)
6 changes: 5 additions & 1 deletion tl.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4019,7 +4019,11 @@ do

store_field_in_record(ps, iv, v.tk, nt.newtype, def.fields, def.field_order)
elseif parse_type_body_fns[tn] and ps.tokens[i + 1].tk ~= ":" then
i = parse_nested_type(ps, i, def, tn)
if def.typename == "interface" and tn == "record" then
i = failskip(ps, i, "interfaces cannot contain record definitions", skip_type_body)
else
i = parse_nested_type(ps, i, def, tn)
end
else
local is_metamethod = false
if ps.tokens[i].tk == "metamethod" and ps.tokens[i + 1].tk ~= ":" then
Expand Down
6 changes: 5 additions & 1 deletion tl.tl
Original file line number Diff line number Diff line change
Expand Up @@ -4019,7 +4019,11 @@ parse_record_body = function(ps: ParseState, i: integer, def: RecordLikeType): i

store_field_in_record(ps, iv, v.tk, nt.newtype, def.fields, def.field_order)
elseif parse_type_body_fns[tn] and ps.tokens[i+1].tk ~= ":" then
i = parse_nested_type(ps, i, def, tn)
if def.typename == "interface" and tn == "record" then
i = failskip(ps, i, "interfaces cannot contain record definitions", skip_type_body)
else
i = parse_nested_type(ps, i, def, tn)
end
else
local is_metamethod = false
if ps.tokens[i].tk == "metamethod" and ps.tokens[i+1].tk ~= ":" then
Expand Down

0 comments on commit f5bb25b

Please sign in to comment.