diff --git a/lib/typeprof/core/env/method.rb b/lib/typeprof/core/env/method.rb index e14141a5..8c7642bd 100644 --- a/lib/typeprof/core/env/method.rb +++ b/lib/typeprof/core/env/method.rb @@ -62,6 +62,23 @@ def get_rest_args(genv, start_rest, end_rest) vtxs.uniq end + + def get_keyword_arg(genv, changes, name) + vtx = Vertex.new(self) + @keywords.each_type do |ty| + case ty + when Type::Hash + changes.add_edge(genv, ty.get_value(name), vtx) + when Type::Instance + if ty.mod == genv.mod_hash + changes.add_edge(genv, ty.args[1], vtx) + end + else + # what to do? + end + end + vtx + end end class Block diff --git a/lib/typeprof/core/graph/box.rb b/lib/typeprof/core/graph/box.rb index 32b1953b..6b0408cd 100644 --- a/lib/typeprof/core/graph/box.rb +++ b/lib/typeprof/core/graph/box.rb @@ -530,33 +530,11 @@ def pass_arguments(changes, genv, a_args) if a_args.keywords # TODO: support diagnostics @node.req_keywords.zip(@f_args.req_keywords) do |name, f_vtx| - a_args.keywords.each_type do |ty| - 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 + changes.add_edge(genv, a_args.get_keyword_arg(genv, changes, name), f_vtx) end @node.opt_keywords.zip(@f_args.opt_keywords).each do |name, f_vtx| - a_args.keywords.each_type do |ty| - 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 + changes.add_edge(genv, a_args.get_keyword_arg(genv, changes, name), f_vtx) end if @node.rest_keywords diff --git a/scenario/args/keyword-twice.rb b/scenario/args/keyword-twice.rb new file mode 100644 index 00000000..21303996 --- /dev/null +++ b/scenario/args/keyword-twice.rb @@ -0,0 +1,37 @@ +## update +class Foo + def initialize(k:) + end +end + +class Bar < Foo +end + +obj = rand < 0.5 ? Foo : Bar +obj.new(k: 1) + +## assert +class Foo + def initialize: (k: Integer) -> nil +end +class Bar < Foo +end + +## update +class Foo + def initialize(k: :default) + end +end + +class Bar < Foo +end + +obj = rand < 0.5 ? Foo : Bar +obj.new(k: 1) + +## assert +class Foo + def initialize: (?k: :default | Integer) -> nil +end +class Bar < Foo +end