Skip to content
This repository has been archived by the owner on Mar 16, 2023. It is now read-only.

Commit

Permalink
Do not crash for '$10' and bigger (fixes #175)
Browse files Browse the repository at this point in the history
  • Loading branch information
jreidinger authored and mvidner committed Jun 25, 2016
1 parent a535662 commit dbd8f96
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 3 deletions.
4 changes: 2 additions & 2 deletions lib/ruby-lint/constant_loader.rb
Expand Up @@ -34,10 +34,10 @@ class ConstantLoader < Iterator
BOOTSTRAP_GVARS = [
'$!', '$$', '$&', '$\'', '$*', '$+', '$,', '$-0', '$-F', '$-I', '$-K',
'$-W', '$-a', '$-d', '$-i', '$-l', '$-p', '$-v', '$-w', '$.', '$/', '$0',
'$1', '$2', '$3', '$4', '$5', '$6', '$7', '$8', '$9', '$:', '$;', '$<',
'$=', '$>', '$?', '$@', '$DEBUG', '$FILENAME', '$KCODE',
'$:', '$;', '$<', '$=', '$>', '$?', '$@', '$DEBUG', '$FILENAME', '$KCODE',
'$LOADED_FEATURES', '$LOAD_PATH', '$PROGRAM_NAME', '$SAFE', '$VERBOSE',
'$\"', '$\\', '$_', '$`', '$stderr', '$stdin', '$stdout', '$~'
# Regexp $1, $2,... $99 are lazy loaded when first used
]

##
Expand Down
2 changes: 2 additions & 0 deletions lib/ruby-lint/virtual_machine.rb
Expand Up @@ -352,6 +352,8 @@ def after_and_asgn
#
def on_nth_ref(node)
var = definitions.lookup(:gvar, "$#{node.children[0]}")
# If the number is not found, then add it as there is no limit for them
var = definitions.define_global_variable(node.children[0]) if !var && node.children[0].is_a?(Fixnum)

push_value(var.value)
end
Expand Down
7 changes: 7 additions & 0 deletions spec/ruby-lint/analysis/undefined_variables_spec.rb
Expand Up @@ -142,4 +142,11 @@ class Bar

report.entries.empty?.should == true
end

it 'does not add errors when using regexp captured global variables' do
code = '$10'
report = build_report(code, RubyLint::Analysis::UndefinedVariables)

report.entries.empty?.should == true
end
end
2 changes: 1 addition & 1 deletion spec/ruby-lint/virtual_machine/global_variables_spec.rb
Expand Up @@ -9,7 +9,7 @@

it 'provides a list of default global variables' do
@defs.lookup(:gvar, '$LOAD_PATH').is_a?(ruby_object).should == true
@defs.lookup(:gvar, '$9').is_a?(ruby_object).should == true
@defs.lookup(:gvar, '$,').is_a?(ruby_object).should == true
end
end
end

0 comments on commit dbd8f96

Please sign in to comment.