From: "eightbitraptor (Matthew Valentine-House)" Date: 2022-12-06T18:27:50+00:00 Subject: [ruby-core:111222] [Ruby master Bug#19167] Object#inspect does not correctly show NilClass TrueClass and FalseClass stored in instance variables Issue #19167 has been updated by eightbitraptor (Matthew Valentine-House). File 0001-Fix-Object-inspect-with-NilClass-as-an-ivar.patch added tompng (tomoya ishida) wrote: > ~~~ruby > Object.new.instance_eval do > @a = nil > @b = NilClass > @c = true > @d = TrueClass > @e = [nil, NilClass, true, TrueClass] > puts self.inspect > end > # actual > # => # > # expected > # => # > ~~~ This is exhibiting the same behaviour on the `master` branch. This looks to be happening because `inspect_i` from `object.c` gets called for each instance variable, and that is using the `PRIsVALUE` macro to print out the values, whereas when we inspect the array in `@e` we use `rb_ary_inspect` which prints each element using `rb_inspect`, and the behaviour of these two differs when being used on `NilClass` and `TrueClass` I agree that this seems like unintended behaviour, and I've attached a possible patch. I haven't yet investigated fully how `PRIsVALUE` works - so my solution may not be the correct one, nor have I investigated whether there is any performance overhead to using `rb_inspect` in the `inspect_i` case. ---------------------------------------- Bug #19167: Object#inspect does not correctly show NilClass TrueClass and FalseClass stored in instance variables https://bugs.ruby-lang.org/issues/19167#change-100512 * Author: tompng (tomoya ishida) * Status: Open * Priority: Normal * ruby -v: ruby 3.1.0p0 (2021-12-25 revision fb4df44d16) [x86_64-darwin20] * Backport: 2.7: UNKNOWN, 3.0: UNKNOWN, 3.1: UNKNOWN ---------------------------------------- ~~~ruby Object.new.instance_eval do @a = nil @b = NilClass @c = true @d = TrueClass @e = [nil, NilClass, true, TrueClass] puts self.inspect end # actual # => # # expected # => # ~~~ ---Files-------------------------------- 0001-Fix-Object-inspect-with-NilClass-as-an-ivar.patch (751 Bytes) -- https://bugs.ruby-lang.org/ ______________________________________________ ruby-core mailing list -- ruby-core@ml.ruby-lang.org To unsubscribe send an email to ruby-core-leave@ml.ruby-lang.org ruby-core info -- https://ml.ruby-lang.org/mailman3/postorius/lists/ruby-core.ml.ruby-lang.org/