Skip to content

Commit

Permalink
Merge pull request #966 from ruby/better_record_syntax_error_handling
Browse files Browse the repository at this point in the history
Raise syntax error from `parse_record_attributes`
  • Loading branch information
soutaro committed Apr 4, 2022
2 parents 53e7470 + bb283d1 commit dc942d8
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
6 changes: 5 additions & 1 deletion ext/rbs_extension/parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -684,7 +684,11 @@ VALUE parse_record_attributes(parserstate *state) {
key = rb_funcall(parse_type(state), rb_intern("literal"), 0);
break;
default:
rbs_abort();
raise_syntax_error(
state,
state->next_token,
"unexpected record key token"
);
}
parser_advance_assert(state, pFATARROW);
}
Expand Down
7 changes: 7 additions & 0 deletions test/rbs/type_parsing_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -594,6 +594,13 @@ def test_record
}, type.fields)
assert_equal "{ foo: untyped, }", type.location.source
end

error = assert_raises(RBS::ParsingError) do
Parser.parse_type("{ foo")
end
assert_equal "tLIDENT", error.token_type
assert_equal "foo", error.location.source
assert_equal "a.rbs:1:2...1:5: Syntax error: unexpected record key token, token=`foo` (tLIDENT)", error.message
end

def test_type_var
Expand Down

0 comments on commit dc942d8

Please sign in to comment.