diff --git a/spec/statement/forin_spec.lua b/spec/statement/forin_spec.lua index b1f38fc7f..11eb26dc9 100644 --- a/spec/statement/forin_spec.lua +++ b/spec/statement/forin_spec.lua @@ -185,6 +185,23 @@ describe("forin", function() })) describe("regression tests", function() + it("does not accept annotations (#701)", util.check_syntax_error([[ + for k , v in pairs(table as {string:any}) do + k = "hello" + print(k, v) + end + ]], { + -- skips one bad token at a time. Too much of a corner case to + -- add parser code just to produce a nicer error, the generic + -- message should be enough to indicate this is not supporter. + { y = 1, msg = "syntax error" }, + { y = 1, msg = "syntax error" }, + { y = 1, msg = "syntax error" }, + { y = 1, msg = "syntax error" }, + { y = 1, msg = "syntax error" }, + { y = 1, msg = "syntax error" }, + })) + it("with an iterator declared as a nominal (#183)", util.check([[ local type Iterator = function(): string diff --git a/tl.lua b/tl.lua index 1d1a8a20f..b4376244c 100644 --- a/tl.lua +++ b/tl.lua @@ -2532,7 +2532,7 @@ local function parse_forin(ps, i) local node = new_node(ps.tokens, i, "forin") i = i + 1 node.vars = new_node(ps.tokens, i, "variable_list") - i, node.vars = parse_list(ps, i, node.vars, { ["in"] = true }, "sep", parse_variable_name) + i, node.vars = parse_list(ps, i, node.vars, { ["in"] = true }, "sep", parse_identifier) i = verify_tk(ps, i, "in") node.exps = new_node(ps.tokens, i, "expression_list") i = parse_list(ps, i, node.exps, { ["do"] = true }, "sep", parse_expression) diff --git a/tl.tl b/tl.tl index 9bf74695c..097316383 100644 --- a/tl.tl +++ b/tl.tl @@ -2382,7 +2382,7 @@ parse_argument_type_list = function(ps: ParseState, i: integer): integer, Type return i, list end -local function parse_identifier(ps: ParseState, i: integer): integer, Node +local function parse_identifier(ps: ParseState, i: integer): integer, Node, integer if ps.tokens[i].kind == "identifier" then return i + 1, new_node(ps.tokens, i, "identifier") end @@ -2532,7 +2532,7 @@ local function parse_forin(ps: ParseState, i: integer): integer, Node local node = new_node(ps.tokens, i, "forin") i = i + 1 node.vars = new_node(ps.tokens, i, "variable_list") - i, node.vars = parse_list(ps, i, node.vars, { ["in"] = true }, "sep", parse_variable_name) + i, node.vars = parse_list(ps, i, node.vars, { ["in"] = true }, "sep", parse_identifier) i = verify_tk(ps, i, "in") node.exps = new_node(ps.tokens, i, "expression_list") i = parse_list(ps, i, node.exps, { ["do"] = true }, "sep", parse_expression)