Skip to content

Commit 965047a

Browse files
committed
Use a type-safe method for getting a class name as not all objects have a class method.
1 parent f27bfd1 commit 965047a

File tree

2 files changed

+7
-7
lines changed

2 files changed

+7
-7
lines changed

src/main/ruby/core/kernel.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ def Hash(obj)
8686
return hash
8787
end
8888

89-
raise TypeError, "can't convert #{obj.class} into Hash"
89+
raise TypeError, "can't convert #{Truffle::Type.object_class(obj)} into Hash"
9090
end
9191
module_function :Hash
9292

src/main/ruby/core/type.rb

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ def self.rb_to_float(val, meth)
226226
end
227227

228228
def self.conversion_mismatch(val, cls, meth, res)
229-
raise TypeError, "can't convert #{val.class} to #{cls} (#{val.class}##{meth} gives #{res.class})"
229+
raise TypeError, "can't convert #{object_class(val)} to #{cls} (#{object_class(val)}##{meth} gives #{object_class(res)})"
230230
end
231231

232232
def self.fits_into_int?(val)
@@ -277,7 +277,7 @@ def self.rb_check_convert_type(obj, cls, meth)
277277
v = convert_type(obj, cls, meth, false)
278278
return nil if v.nil?
279279
unless object_kind_of?(v, cls)
280-
raise TypeError, "can't convert #{obj.class} to #{cls} (#{obj.class}##{meth} gives #{v.class})"
280+
raise TypeError, "can't convert #{object_class(obj)} to #{cls} (#{object_class(obj)}##{meth} gives #{object_class(v)})"
281281
end
282282
v
283283
end
@@ -286,14 +286,14 @@ def self.rb_convert_type(obj, cls, meth)
286286
return obj if object_kind_of?(obj, cls)
287287
v = convert_type(obj, cls, meth, true)
288288
unless object_kind_of?(v, cls)
289-
raise TypeError, "can't convert #{obj.class} to #{cls} (#{obj.class}##{meth} gives #{v.class})"
289+
raise TypeError, "can't convert #{object_class(obj)} to #{cls} (#{object_class(obj)}##{meth} gives #{object_class(v)})"
290290
end
291291
v
292292
end
293293

294294
def self.rb_check_type(obj, cls)
295295
unless object_kind_of?(obj, cls)
296-
raise TypeError, "wrong argument type #{obj.class} (expected #{cls})"
296+
raise TypeError, "wrong argument type #{object_class(obj)} (expected #{cls})"
297297
end
298298
obj
299299
end
@@ -302,7 +302,7 @@ def self.convert_type(obj, cls, meth, raise_on_error)
302302
r = check_funcall(obj, meth)
303303
if undefined.equal?(r)
304304
if raise_on_error
305-
raise TypeError, "can't convert #{obj.class} into #{cls} with #{meth}"
305+
raise TypeError, "can't convert #{object_class(obj)} into #{cls} with #{meth}"
306306
end
307307
return nil
308308
end
@@ -439,7 +439,7 @@ def self.coerce_to_float(obj)
439439
when nil, true, false
440440
raise TypeError, "can't convert #{obj.inspect} into Float"
441441
else
442-
raise TypeError, "can't convert #{obj.class} into Float"
442+
raise TypeError, "can't convert #{object_class(obj)} into Float"
443443
end
444444
end
445445

0 commit comments

Comments
 (0)