[Feature #20884] Reserve "Ruby" toplevel name

This commit is contained in:
Nobuyoshi Nakada 2024-12-12 15:59:25 +09:00 committed by Nobuyoshi Nakada
parent 267ecf5f02
commit 4d86f3bf6d
Notes: git 2024-12-12 08:45:24 +00:00
3 changed files with 20 additions and 0 deletions

View File

@ -101,6 +101,8 @@ firstline, predefined = __LINE__+1, %[\
$_ LASTLINE
$~ BACKREF
$! ERROR_INFO
Ruby
]
# VM ID OP Parser Token

View File

@ -1326,4 +1326,19 @@ class TestRubyOptions < Test::Unit::TestCase
assert_ruby_status([env, "-e;"])
assert_in_out_err([env, "-W"], "", [], /Free at exit is experimental and may be unstable/)
end
def test_toplevel_ruby
reserved = ["", [], /::Ruby is reserved/]
env = {"RUBYOPT"=>""}
args = %w[-e Ruby=1]
assert_in_out_err([env, *args])
assert_in_out_err([env, "-w", *args], *reserved)
assert_in_out_err([env, "-W:deprecated", *args], *reserved)
assert_in_out_err([env, "-w", "-W:no-deprecated", *args])
args = ["-e", "class A; Ruby=1; end"]
assert_in_out_err([env, *args])
assert_in_out_err([env, "-w", *args])
assert_in_out_err([env, "-W:deprecated", *args])
end
end

View File

@ -3626,6 +3626,9 @@ const_set(VALUE klass, ID id, VALUE val)
}
}
}
if (klass == rb_cObject && id == idRuby) {
rb_warn_reserved_name_at(3.5, "::Ruby");
}
}
void