Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix double-edge error when the same keyword hash is passed to a method #257

Merged
merged 1 commit into from
Aug 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions lib/typeprof/core/env/method.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
26 changes: 2 additions & 24 deletions lib/typeprof/core/graph/box.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
37 changes: 37 additions & 0 deletions scenario/args/keyword-twice.rb
Original file line number Diff line number Diff line change
@@ -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