Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Raise syntax error from parse_record_attributes #966

Merged
merged 1 commit into from
Apr 4, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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