Skip to content

Commit 539713d

Browse files
committed
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.
1 parent 95c8e79 commit 539713d

4 files changed

Lines changed: 31 additions & 2 deletions

File tree

lib/typeprof/core/graph/box.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -662,11 +662,11 @@ def show(output_parameter_names)
662662
names = []
663663
names.concat(@node.req_positionals)
664664
names.concat(@node.opt_positionals)
665-
names.concat(@node.rest_positionals) if @node.rest_positionals
665+
names << @node.rest_positionals if @node.rest_positionals
666666
names.concat(@node.post_positionals)
667667
names.concat(@node.req_keywords)
668668
names.concat(@node.opt_keywords)
669-
names.concat(@node.rest_keywords) if @node.rest_keywords
669+
names << @node.rest_keywords if @node.rest_keywords
670670
args = args.zip(names).map do |arg, name|
671671
name ? "#{ arg } #{ name }" : arg
672672
end

test/cli_test.rb

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,18 @@ def foo: (String n) -> String
7676
END
7777
end
7878

79+
def test_e2e_output_param_names_rest
80+
assert_equal(<<~END, test_run("rest_params", ["--show-parameter-names", "."]))
81+
# TypeProf #{ TypeProf::VERSION }
82+
83+
# ./rest_params.rb
84+
class Object
85+
def foo: (*Integer args) -> Array[Integer]
86+
def bar: (**String kwargs) -> { x: String }
87+
end
88+
END
89+
end
90+
7991
def test_e2e_output_source_location
8092
assert_equal(<<~END, test_run("basic", ["--show-source-location", "."]))
8193
# TypeProf #{ TypeProf::VERSION }
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
def foo(*args)
2+
args
3+
end
4+
5+
def bar(**kwargs)
6+
kwargs
7+
end
8+
9+
foo(1)
10+
bar(x: "str")
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"typeprof_version": "experimental",
3+
"rbs_dir": "sig/",
4+
"analysis_unit_dirs": [
5+
"."
6+
]
7+
}

0 commit comments

Comments
 (0)