From 258694917ae9ba1a973fc5fc2ed6515ecace1923 Mon Sep 17 00:00:00 2001 From: Yusuke Endoh Date: Thu, 8 Aug 2024 15:14:09 +0900 Subject: [PATCH] Tentative support of keyword splat --- lib/typeprof/core/graph/box.rb | 22 ++++++++++++++++++++-- scenario/args/keyword_splat.rb | 11 +++++++++++ 2 files changed, 31 insertions(+), 2 deletions(-) create mode 100644 scenario/args/keyword_splat.rb diff --git a/lib/typeprof/core/graph/box.rb b/lib/typeprof/core/graph/box.rb index 378b616de..bec75bb02 100644 --- a/lib/typeprof/core/graph/box.rb +++ b/lib/typeprof/core/graph/box.rb @@ -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 diff --git a/scenario/args/keyword_splat.rb b/scenario/args/keyword_splat.rb new file mode 100644 index 000000000..d97d80883 --- /dev/null +++ b/scenario/args/keyword_splat.rb @@ -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