Skip to content

Commit

Permalink
Tentative support of keyword splat
Browse files Browse the repository at this point in the history
  • Loading branch information
mame committed Aug 8, 2024
1 parent 59f1c86 commit 2586949
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 2 deletions.
22 changes: 20 additions & 2 deletions lib/typeprof/core/graph/box.rb
Original file line number Diff line number Diff line change
Expand Up @@ -531,13 +531,31 @@ def pass_arguments(changes, genv, a_args)
# TODO: support diagnostics
@node.req_keywords.zip(@f_args.req_keywords) do |name, f_vtx|
a_args.keywords.each_type do |ty|
changes.add_edge(genv, ty.get_value(name), f_vtx)
case ty
when Type::Hash
changes.add_edge(genv, ty.get_value(name), f_vtx)
when Type::Instance
if ty.mod == genv.mod_hash
changes.add_edge(genv, ty.args[1], f_vtx)
end
else
# what to do?
end
end
end

@node.opt_keywords.zip(@f_args.opt_keywords).each do |name, f_vtx|
a_args.keywords.each_type do |ty|
changes.add_edge(genv, ty.get_value(name), f_vtx)
case ty
when Type::Hash
changes.add_edge(genv, ty.get_value(name), f_vtx)
when Type::Instance
if ty.mod == genv.mod_hash
changes.add_edge(genv, ty.args[1], f_vtx)
end
else
# what to do?
end
end
end

Expand Down
11 changes: 11 additions & 0 deletions scenario/args/keyword_splat.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
## update
def foo(check: false)
end

opt = { foo: 1 }
foo(**opt) # I am not sure what is the best here, but tentatively...

## assert
class Object
def foo: (?check: Integer | false) -> nil
end

0 comments on commit 2586949

Please sign in to comment.