Skip to content

Commit

Permalink
Update NoMethodError message to not use object#inspect
Browse files Browse the repository at this point in the history
  • Loading branch information
rwstauner committed Dec 17, 2024
1 parent ef17fc7 commit 3bdc5ea
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 8 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ Compatibility:
* Support `symbolize_names` argument to `MatchData#named_captures` (#3681, @rwstauner).
* Support `Proc#initialize_{dup,copy}` for subclasses (#3681, @rwstauner).
* Remove deprecated `Encoding#replicate` method (#3681, @rwstauner).
* Update NoMethodError message to not use object#inspect (#3681, @rwstauner).

Performance:

Expand Down
1 change: 0 additions & 1 deletion spec/tags/core/exception/no_method_error_tags.txt

This file was deleted.

22 changes: 15 additions & 7 deletions src/main/ruby/truffleruby/core/truffle/exception_operations.rb
Original file line number Diff line number Diff line change
Expand Up @@ -75,20 +75,28 @@ def self.class_name(receiver)
# MRI: name_err_mesg_to_str
def self.receiver_string(receiver)
ret = begin
if Primitive.respond_to?(receiver, :inspect, false)
case receiver
when NilClass, TrueClass, FalseClass
Truffle::Type.rb_inspect(receiver)
when Class
unless receiver.singleton_class?
"class #{receiver}"
end
# otherwise fall through to rb_any_to_s
when Module
"module #{receiver}"
else
nil
klass = Primitive.metaclass(receiver)
if klass.name
"an instance of #{klass.name}"
end
# else fall through to rb_any_to_s
end
rescue Exception # rubocop:disable Lint/RescueException
nil
end
ret = Primitive.rb_any_to_s(receiver) unless ret && ret.bytesize <= 65
if ret.start_with?('#')
ret
else
"#{ret}:#{class_name(receiver)}"
end
ret
end

# MRI: inspect_frozen_obj
Expand Down

0 comments on commit 3bdc5ea

Please sign in to comment.