Skip to content

Commit

Permalink
[Feature #20884] Reserve "Ruby" toplevel name
Browse files Browse the repository at this point in the history
  • Loading branch information
nobu committed Dec 12, 2024
1 parent 267ecf5 commit 4d86f3b
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 0 deletions.
2 changes: 2 additions & 0 deletions defs/id.def
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,8 @@ firstline, predefined = __LINE__+1, %[\
$_ LASTLINE
$~ BACKREF
$! ERROR_INFO
Ruby
]

# VM ID OP Parser Token
Expand Down
15 changes: 15 additions & 0 deletions test/ruby/test_rubyoptions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1326,4 +1326,19 @@ def test_free_at_exit_env_var
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
3 changes: 3 additions & 0 deletions variable.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 4d86f3b

Please sign in to comment.