From b9fd6ccca8e1867aadc18bda109ede7d28a51373 Mon Sep 17 00:00:00 2001 From: ksss Date: Tue, 17 Mar 2026 16:28:45 +0900 Subject: [PATCH] Fix `() -> (void)` being rejected as SyntaxError `void_allowed` was hardcoded to `false` when parsing a parenthesized type, causing `(void)` to be rejected even in return type positions where `void` is valid. --- src/parser.c | 2 +- test/rbs/method_type_parsing_test.rb | 6 ++++++ test/rbs/type_parsing_test.rb | 5 +++++ 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/parser.c b/src/parser.c index be238c7599..cf7c9e8802 100644 --- a/src/parser.c +++ b/src/parser.c @@ -1120,7 +1120,7 @@ static bool parse_simple(rbs_parser_t *parser, rbs_node_t **type, bool void_allo switch (parser->current_token.type) { case pLPAREN: { rbs_node_t *lparen_type; - CHECK_PARSE(rbs_parse_type(parser, &lparen_type, false, self_allowed, classish_allowed)); + CHECK_PARSE(rbs_parse_type(parser, &lparen_type, void_allowed, self_allowed, classish_allowed)); ADVANCE_ASSERT(parser, pRPAREN); *type = lparen_type; return true; diff --git a/test/rbs/method_type_parsing_test.rb b/test/rbs/method_type_parsing_test.rb index fd04ed718c..c6b561faf1 100644 --- a/test/rbs/method_type_parsing_test.rb +++ b/test/rbs/method_type_parsing_test.rb @@ -32,6 +32,12 @@ def test_method_type Parser.parse_method_type("(?foo?: Integer, ?bar!: String)->void") end + def test_method_type__void_in_paren + Parser.parse_method_type("() -> (void)").tap do |type| + assert_instance_of Types::Bases::Void, type.type.return_type + end + end + def test_method_param Parser.parse_method_type("(untyped _, top __, Object _2, String _abc_123)->void").yield_self do |type| assert_equal "(untyped _, top __, Object _2, String _abc_123) -> void", type.to_s diff --git a/test/rbs/type_parsing_test.rb b/test/rbs/type_parsing_test.rb index c140442f83..97c5754b95 100644 --- a/test/rbs/type_parsing_test.rb +++ b/test/rbs/type_parsing_test.rb @@ -925,6 +925,11 @@ def test_parse__void__return_types Parser.parse_type("^() { () -> void } -> void").tap do |type| assert_instance_of Types::Proc, type end + + Parser.parse_type("^() -> (void)").tap do |type| + assert_instance_of Types::Proc, type + assert_instance_of Types::Bases::Void, type.type.return_type + end end def test_parse__void__prohibited