Skip to content

Commit

Permalink
Warn when $= is used
Browse files Browse the repository at this point in the history
  • Loading branch information
andrykonchin committed Jun 20, 2022
1 parent 5132a08 commit b4625f3
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 1 deletion.
26 changes: 26 additions & 0 deletions spec/ruby/language/predefined_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1378,3 +1378,29 @@ def obj.foo2; yield; end
end
end
end

# Some other pre-defined global variables

describe "Predefined global $=" do
before :each do
@verbose, $VERBOSE = $VERBOSE, nil
@dollar_assign = $=
end

after :each do
$= = @dollar_assign
$VERBOSE = @verbose
end

it "warns when accessed" do
-> { a = $= }.should complain(/is no longer effective/)
end

it "warns when assigned" do
-> { $= = "_" }.should complain(/is no longer effective/)
end

it "returns the value assigned" do
($= = "xyz").should == "xyz"
end
end
13 changes: 12 additions & 1 deletion src/main/ruby/truffleruby/core/truffle/kernel_operations.rb
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,18 @@ def $LOAD_PATH.resolve_feature_path(file_name)

$, = nil # It should be defined by the time boot has finished.

$= = false
define_hooked_variable(
:$=,
-> {
warn 'variable $= is no longer effective', uplevel: 1 if Warning[:deprecated]
Primitive.global_variable_get :$=
},
-> v {
warn 'variable $= is no longer effective', uplevel: 1 if Warning[:deprecated]
Primitive.global_variable_set :$=, v
})

Primitive.global_variable_set :$=, false

define_hooked_variable(
:$VERBOSE,
Expand Down

0 comments on commit b4625f3

Please sign in to comment.