From 9ffdc83474daef704f5aa5bb953b324daaeab588 Mon Sep 17 00:00:00 2001 From: Yusuke Endoh Date: Tue, 24 Feb 2026 12:16:49 +0000 Subject: [PATCH] Fix TypeError for rest_positionals/rest_keywords in method signature display rest_positionals and rest_keywords are single Symbols, not Arrays, so use << instead of concat. --- lib/typeprof/core/graph/box.rb | 4 ++-- test/cli_test.rb | 12 ++++++++++++ test/fixtures/rest_params/rest_params.rb | 10 ++++++++++ test/fixtures/rest_params/typeprof.conf.json | 7 +++++++ 4 files changed, 31 insertions(+), 2 deletions(-) create mode 100644 test/fixtures/rest_params/rest_params.rb create mode 100644 test/fixtures/rest_params/typeprof.conf.json diff --git a/lib/typeprof/core/graph/box.rb b/lib/typeprof/core/graph/box.rb index e06600e33..15a1c67e5 100644 --- a/lib/typeprof/core/graph/box.rb +++ b/lib/typeprof/core/graph/box.rb @@ -662,11 +662,11 @@ def show(output_parameter_names) names = [] names.concat(@node.req_positionals) names.concat(@node.opt_positionals) - names.concat(@node.rest_positionals) if @node.rest_positionals + names << @node.rest_positionals if @node.rest_positionals names.concat(@node.post_positionals) names.concat(@node.req_keywords) names.concat(@node.opt_keywords) - names.concat(@node.rest_keywords) if @node.rest_keywords + names << @node.rest_keywords if @node.rest_keywords args = args.zip(names).map do |arg, name| name ? "#{ arg } #{ name }" : arg end diff --git a/test/cli_test.rb b/test/cli_test.rb index 3d14a476a..0bf240a08 100644 --- a/test/cli_test.rb +++ b/test/cli_test.rb @@ -76,6 +76,18 @@ def foo: (String n) -> String END end + def test_e2e_output_param_names_rest + assert_equal(<<~END, test_run("rest_params", ["--show-parameter-names", "."])) + # TypeProf #{ TypeProf::VERSION } + + # ./rest_params.rb + class Object + def foo: (*Integer args) -> Array[Integer] + def bar: (**String kwargs) -> { x: String } + end + END + end + def test_e2e_output_source_location assert_equal(<<~END, test_run("basic", ["--show-source-location", "."])) # TypeProf #{ TypeProf::VERSION } diff --git a/test/fixtures/rest_params/rest_params.rb b/test/fixtures/rest_params/rest_params.rb new file mode 100644 index 000000000..682635b26 --- /dev/null +++ b/test/fixtures/rest_params/rest_params.rb @@ -0,0 +1,10 @@ +def foo(*args) + args +end + +def bar(**kwargs) + kwargs +end + +foo(1) +bar(x: "str") diff --git a/test/fixtures/rest_params/typeprof.conf.json b/test/fixtures/rest_params/typeprof.conf.json new file mode 100644 index 000000000..eec7817ee --- /dev/null +++ b/test/fixtures/rest_params/typeprof.conf.json @@ -0,0 +1,7 @@ +{ + "typeprof_version": "experimental", + "rbs_dir": "sig/", + "analysis_unit_dirs": [ + "." + ] +}