Skip to content

Commit

Permalink
Restrict refute_send_type to check method call doesn't match with type
Browse files Browse the repository at this point in the history
  • Loading branch information
pocke committed Feb 7, 2021
1 parent 700a8ed commit e1b2b36
Showing 1 changed file with 18 additions and 11 deletions.
29 changes: 18 additions & 11 deletions test/stdlib/test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -239,17 +239,7 @@ def testing(type_or_string)

assert_empty errors.map {|x| RBS::Test::Errors.to_string(x) }, "Call trace does not match with given method type: #{trace.last.inspect}"

type, definition = target
method_types = case
when definition.instance_type?
subst = RBS::Substitution.build(definition.type_params, type.args)
definition.methods[method].method_types.map do |method_type|
method_type.sub(subst)
end
when definition.class_type?
definition.methods[method].method_types
end

method_types = method_types(method)
all_errors = method_types.map {|t| typecheck.method_call(method, t, trace.last, errors: []) }
assert all_errors.any? {|es| es.empty? }, "Call trace does not match one of method definitions:\n #{trace.last.inspect}\n #{method_types.join(" | ")}"

Expand Down Expand Up @@ -293,8 +283,25 @@ def testing(type_or_string)
assert_operator exception, :is_a?, ::Exception
assert_empty errors.map {|x| RBS::Test::Errors.to_string(x) }

method_types = method_types(method)
all_errors = method_types.map {|t| typecheck.method_call(method, t, trace.last, errors: []) }
assert all_errors.all? {|es| es.size > 0 }, "Call trace unexpectedly matches one of method definitions:\n #{trace.last.inspect}\n #{method_types.join(" | ")}"

result
end

def method_types(method)
type, definition = target
case
when definition.instance_type?
subst = RBS::Substitution.build(definition.type_params, type.args)
definition.methods[method].method_types.map do |method_type|
method_type.sub(subst)
end
when definition.class_type?
definition.methods[method].method_types
end
end
end

class ToInt
Expand Down

0 comments on commit e1b2b36

Please sign in to comment.