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

Make {Nil,True,False}Class#singleton_method always raise NameError #7973

Merged
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 3 additions & 4 deletions proc.c
Expand Up @@ -2096,10 +2096,9 @@ rb_obj_singleton_method(VALUE obj, VALUE vid)
VALUE klass = rb_singleton_class_get(obj);
ID id = rb_check_id(&vid);

if (NIL_P(klass)) {
/* goto undef; */
}
else if (NIL_P(klass = RCLASS_ORIGIN(klass))) {
if (NIL_P(klass) ||
NIL_P(klass = RCLASS_ORIGIN(klass)) ||
!NIL_P(rb_special_singleton_class(obj))) {
/* goto undef; */
}
else if (! id) {
Expand Down
15 changes: 15 additions & 0 deletions spec/ruby/core/false/singleton_method_spec.rb
@@ -0,0 +1,15 @@
require_relative '../../spec_helper'

describe "FalseClass#singleton_method" do
ruby_version_is '3.3' do
it "raises regardless of whether FalseClass defines the method" do
proc{false.singleton_method(:foo)}.should raise_error(NameError)
begin
def false.foo; end
proc{false.singleton_method(:foo)}.should raise_error(NameError)
ensure
FalseClass.send(:remove_method, :foo)
end
end
end
end
15 changes: 15 additions & 0 deletions spec/ruby/core/nil/singleton_method_spec.rb
@@ -0,0 +1,15 @@
require_relative '../../spec_helper'

describe "NilClass#singleton_method" do
ruby_version_is '3.3' do
it "raises regardless of whether NilClass defines the method" do
proc{nil.singleton_method(:foo)}.should raise_error(NameError)
begin
def nil.foo; end
proc{nil.singleton_method(:foo)}.should raise_error(NameError)
ensure
NilClass.send(:remove_method, :foo)
end
end
end
end
15 changes: 15 additions & 0 deletions spec/ruby/core/true/singleton_method_spec.rb
@@ -0,0 +1,15 @@
require_relative '../../spec_helper'

describe "TrueClass#singleton_method" do
ruby_version_is '3.3' do
it "raises regardless of whether TrueClass defines the method" do
proc{true.singleton_method(:foo)}.should raise_error(NameError)
begin
def true.foo; end
proc{true.singleton_method(:foo)}.should raise_error(NameError)
ensure
TrueClass.send(:remove_method, :foo)
end
end
end
end