Skip to content

Commit 1dc62ef

Browse files
authored
Merge pull request #2884 from ksss/fix-void-in-paren
Fix `() -> (void)` being rejected as SyntaxError
2 parents c46454b + b9fd6cc commit 1dc62ef

File tree

3 files changed

+12
-1
lines changed

3 files changed

+12
-1
lines changed

src/parser.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1160,7 +1160,7 @@ static bool parse_simple(rbs_parser_t *parser, rbs_node_t **type, bool void_allo
11601160
switch (parser->current_token.type) {
11611161
case pLPAREN: {
11621162
rbs_node_t *lparen_type;
1163-
CHECK_PARSE(rbs_parse_type(parser, &lparen_type, false, self_allowed, classish_allowed));
1163+
CHECK_PARSE(rbs_parse_type(parser, &lparen_type, void_allowed, self_allowed, classish_allowed));
11641164
ADVANCE_ASSERT(parser, pRPAREN);
11651165
*type = lparen_type;
11661166
return true;

test/rbs/method_type_parsing_test.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,12 @@ def test_method_type
3232
Parser.parse_method_type("(?foo?: Integer, ?bar!: String)->void")
3333
end
3434

35+
def test_method_type__void_in_paren
36+
Parser.parse_method_type("() -> (void)").tap do |type|
37+
assert_instance_of Types::Bases::Void, type.type.return_type
38+
end
39+
end
40+
3541
def test_method_param
3642
Parser.parse_method_type("(untyped _, top __, Object _2, String _abc_123)->void").yield_self do |type|
3743
assert_equal "(untyped _, top __, Object _2, String _abc_123) -> void", type.to_s

test/rbs/type_parsing_test.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -925,6 +925,11 @@ def test_parse__void__return_types
925925
Parser.parse_type("^() { () -> void } -> void").tap do |type|
926926
assert_instance_of Types::Proc, type
927927
end
928+
929+
Parser.parse_type("^() -> (void)").tap do |type|
930+
assert_instance_of Types::Proc, type
931+
assert_instance_of Types::Bases::Void, type.type.return_type
932+
end
928933
end
929934

930935
def test_parse__void__prohibited

0 commit comments

Comments
 (0)