diff --git a/spec/lang/declaration/record_spec.lua b/spec/lang/declaration/record_spec.lua index 99ee580f..50e7b204 100644 --- a/spec/lang/declaration/record_spec.lua +++ b/spec/lang/declaration/record_spec.lua @@ -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) diff --git a/tl.lua b/tl.lua index dcf42fee..5335ffdd 100644 --- a/tl.lua +++ b/tl.lua @@ -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 diff --git a/tl.tl b/tl.tl index 893df647..7720d1e1 100644 --- a/tl.tl +++ b/tl.tl @@ -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