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 klass name if klass is singleton_class #1695

Merged
merged 1 commit into from
Dec 21, 2023
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
7 changes: 6 additions & 1 deletion lib/rbs/test/errors.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,12 @@ def self.inspect_(obj)
end

def self.to_string(error)
method = "#{error.klass.name}#{error.method_name}"
name = if error.klass.singleton_class?
inspect_(error.klass).sub(/\A#<Class:(.*)>\z/, '\1')
else
error.klass.name
end
method = "#{name}#{error.method_name}"
case error
when ArgumentTypeError
"[#{method}] ArgumentTypeError: expected #{format_param error.param} but given `#{inspect_(error.value)}`"
Expand Down
26 changes: 26 additions & 0 deletions test/rbs/test/type_check_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,32 @@ def test_typecheck_return
end
end

def test_typecheck_return_singleton
SignatureManager.new do |manager|
manager.build do |env|
typecheck = Test::TypeCheck.new(
self_class: Object.singleton_class,
builder: DefinitionBuilder.new(env: env),
sample_size: 100,
unchecked_classes: []
)

parse_method_type("() -> Integer").tap do |method_type|
errors = []
typecheck.return ".foo",
method_type,
method_type.type,
Test::ArgumentsReturn.return(arguments: [], value: 'a'),
errors,
return_error: Test::Errors::ReturnTypeError

assert_equal 1, errors.size
assert_equal "[Object.foo] ReturnTypeError: expected `Integer` but returns `\"a\"`", RBS::Test::Errors.to_string(errors.first)
end
end
end
end

def test_type_check_record
SignatureManager.new do |manager|
manager.files[Pathname("foo.rbs")] = <<EOF
Expand Down