Skip to content

Commit 29d382a

Browse files
sinsokuclaude
andauthored
Fix RBS::ParsingError when block argument is assigned to rest keywords hash (#358)
The following code caused RBS::ParsingError: ```ruby # issue.rb def foo(**opts, &block) opts[:callback] = block opts end foo(key: 1) {} ``` ```bash $ bin/typeprof issue.rb # TypeProf 0.31.1 # issue.rb /Users/sinsoku/.local/share/mise/installs/ruby/4.0.0/lib/ruby/gems/4.0.0/gems/rbs-3.10.0/lib/rbs/parser_aux.rb:10:in 'RBS::Parser._parse_type': RBS::ParsingError from /Users/sinsoku/.local/share/mise/installs/ruby/4.0.0/lib/ruby/gems/4.0.0/gems/rbs-3.10.0/lib/rbs/parser_aux.rb:10:in 'RBS::Parser.parse_type' from /Users/sinsoku/ghq/github.com/ruby/typeprof/lib/typeprof/core/type.rb:20:in 'TypeProf::Core::Type.extract_hash_value_type' from /Users/sinsoku/ghq/github.com/ruby/typeprof/lib/typeprof/core/graph/box.rb:647:in 'TypeProf::Core::MethodDefBox#show' ``` Type::Proc#show returned "<Proc>" which is not valid RBS syntax. MethodDefBox#show calls extract_hash_value_type to parse rest_keywords type with RBS::Parser, causing ParsingError when the type contains "<Proc>". Changed Type::Proc#show to return "Proc" for RBS compatibility. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
1 parent 491d555 commit 29d382a

2 files changed

Lines changed: 13 additions & 1 deletion

File tree

lib/typeprof/core/type.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ def base_type(genv)
188188
end
189189

190190
def show
191-
"<Proc>"
191+
"Proc"
192192
end
193193
end
194194

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
## update
2+
def foo(**opts, &block)
3+
opts[:callback] = block
4+
opts
5+
end
6+
7+
foo(key: 1) {}
8+
9+
## assert
10+
class Object
11+
def foo: (**Integer | Proc) -> Hash[:key, Integer | Proc]
12+
end

0 commit comments

Comments
 (0)