Skip to content

Commit

Permalink
Merge pull request #1688 from ksss/UnresolvedOverloadingError-details
Browse files Browse the repository at this point in the history
Add more details error message for UnresolvedOverloadingError
  • Loading branch information
soutaro authored Dec 19, 2023
2 parents 2fdb2e9 + 561f446 commit 3a965cb
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 15 deletions.
11 changes: 11 additions & 0 deletions lib/rbs/test/type_check.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,17 @@ def overloaded_call(method, method_name, call, errors:)
if es.size == 1
errors.push(*es[0])
else
RBS.logger.warn do
message = +"[#{self_class}#{method_name}] UnresolvedOverloadingError "
message << method.method_types.zip(es).map do |method_type, es|
msg = +"method_type=`#{method_type}`"
details = es.map do |e|
"\"#{Errors.to_string(e).sub("[#{e.klass.name}#{e.method_name}] ", "") }\""
end.join(', ')
msg << " details=[#{details}]"
end.join(', ')
message
end
errors << Errors::UnresolvedOverloadingError.new(
klass: self_class,
method_name: method_name,
Expand Down
36 changes: 21 additions & 15 deletions test/rbs/test/type_check_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -517,22 +517,28 @@ def bar: () -> String
assert_instance_of RBS::Test::Errors::ReturnTypeError, errors[0]
end

typecheck.overloaded_call(
foo.methods[:foo],
"#foo",
Test::CallTrace.new(
method_name: :foo,
method_call: Test::ArgumentsReturn.return(
arguments: [3],
value: 30
begin
RBS.logger_output = logger = StringIO.new
typecheck.overloaded_call(
foo.methods[:foo],
"#foo",
Test::CallTrace.new(
method_name: :foo,
method_call: Test::ArgumentsReturn.return(
arguments: [3],
value: 30
),
block_calls: [],
block_given: false
),
block_calls: [],
block_given: false
),
errors: []
).tap do |errors|
assert_equal 1, errors.size
assert_instance_of RBS::Test::Errors::UnresolvedOverloadingError, errors[0]
errors: []
).tap do |errors|
assert_equal 1, errors.size
assert_instance_of RBS::Test::Errors::UnresolvedOverloadingError, errors[0]
assert_match '[Object#foo] UnresolvedOverloadingError method_type=`() -> ::String` details=["ArgumentError: expected method type () -> ::String", "ReturnTypeError: expected `::String` but returns `30`"], method_type=`(::Integer) -> ::String` details=["ReturnTypeError: expected `::String` but returns `30`"]', logger.string
end
ensure
RBS.logger_output = nil
end
end
end
Expand Down

0 comments on commit 3a965cb

Please sign in to comment.