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

Commit

Permalink
Merge pull request #187 from mvidner/not-enough-argument-definitions
Browse files Browse the repository at this point in the history
Fix 'Not enough argument definitions' exception when parsing less usual constructs
  • Loading branch information
Yorick Peterse committed Jun 27, 2016
2 parents 6f67533 + 6f2de63 commit c9a3e27
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/ruby-lint/variable_predicates.rb
Expand Up @@ -20,6 +20,7 @@ module VariablePredicates
#
RUBY_CLASSES = {
:str => 'String',
:dstr => 'String',
:sym => 'Symbol',
:int => 'Fixnum',
:float => 'Float',
Expand Down
9 changes: 9 additions & 0 deletions lib/ruby-lint/virtual_machine.rb
Expand Up @@ -103,7 +103,9 @@ class VirtualMachine < Iterator
:int,
:float,
:str,
:dstr,
:sym,
:regexp,
:true,
:false,
:nil,
Expand Down Expand Up @@ -448,6 +450,13 @@ def on_self
push_value(method.return_value)
end

##
# Pushes the return value of the block yielded to, that is, an unknown one.
#
def on_yield
push_unknown_value
end

##
# Creates the definition for a module.
#
Expand Down
34 changes: 34 additions & 0 deletions spec/ruby-lint/virtual_machine/assignments/return_values_spec.rb
Expand Up @@ -38,19 +38,53 @@ def example
value.instance?.should == true
end

it 'assigns a return value for a bare yield' do
code = <<-CODE
number = yield
CODE

defs = build_definitions(code)

defs.lookup(:lvar, 'number').value.should_not == nil
end


describe 'setting instance types for core Ruby types' do
it 'creates a new String instance' do
defs = build_definitions('number = "10"')

defs.lookup(:lvar, 'number').value.instance?.should == true
end

it 'creates a new interpolated String instance' do
defs = build_definitions('number = "#{1}#{0}"')

defs.lookup(:lvar, 'number').value.instance?.should == true
end

it 'creates a new heredoc String instance' do
code = <<-CODE
number = <<EOS
EOS
CODE

defs = build_definitions(code)

defs.lookup(:lvar, 'number').value.instance?.should == true
end

it 'creates a new Symbol instance' do
defs = build_definitions('number = :"10"')

defs.lookup(:lvar, 'number').value.instance?.should == true
end

it 'creates a new Regexp instance' do
defs = build_definitions('number = //')

defs.lookup(:lvar, 'number').value.instance?.should == true
end

it 'creates a new Fixnum instance' do
defs = build_definitions('number = 10')

Expand Down

0 comments on commit c9a3e27

Please sign in to comment.