Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Truffle] Error calling block in optparse for MRI tests. #2823

Closed
bjfish opened this issue Apr 12, 2015 · 3 comments
Closed

[Truffle] Error calling block in optparse for MRI tests. #2823

bjfish opened this issue Apr 12, 2015 · 3 comments

Comments

@bjfish
Copy link
Contributor

bjfish commented Apr 12, 2015

Currently, blocking running the MRI tests.

Example:

class ExampleHash < Hash

    def self.regexp(key, icase)
      Regexp.new('\A' + Regexp.quote(key).gsub(/\w+\b/, '\&\w*'), icase)
    end

    def self.candidate(key, icase = false, pat = nil, &block)
      pat ||= ExampleHash.regexp(key, icase)
      candidates = []
      puts "block #{block}"
      block.call do |k, *v|
        puts "INBLOCK"
        (if Regexp === k
           kn = nil
           k === key
         else
           kn = defined?(k.id2name) ? k.id2name : k
           pat === kn
         end) or next
        v << k if v.empty?
        candidates << [k, v, kn]
      end
      candidates
    end

    def candidates(key, icase = false, pat = nil)
      ExampleHash.candidate(key, icase, pat, &method(:each))
    end

    def test
      candidates( "no", false, /(?-mix:\Ano\w*)/ , &method(:each) )
    end

end

puts "`#{ExampleHash[ :no ,"no" ].test}`"

Expected

block #<Proc:0x007fced98e8fa0 (lambda)>
INBLOCK
`[[:no, ["no"], "no"]]`

Actual

block #<Proc:0xe0@core:/core/shims.rb:121>
`[]`

@bjfish
Copy link
Contributor Author

bjfish commented Apr 14, 2015

The change in optparse.rb can be used to workaround this issue to run jt test mri tests:
https://gist.github.com/bjfish/1be84623da4a746f4d16

@bjfish bjfish changed the title [Truffle] Error calling block in optparse. [Truffle] Error calling block in optparse for MRI tests. Apr 14, 2015
@chrisseaton chrisseaton added this to the truffle-dev milestone Apr 14, 2015
@chrisseaton
Copy link
Contributor

Simpler case:

def bar
  yield 14
end

def foo(&block)
  block.call do |x|
    puts x
  end
end

foo &method(:bar)
$ ruby ../test.rb 
14
$ jt run ../test.rb 
../test.rb:2:in `bar': no block given (yield) (LocalJumpError)
  from core:/core/shims.rb:121:in `call'
  from core:/core/shims.rb:121:in `block in to_proc'
  from ../test.rb:6:in `call'
  from ../test.rb:6:in `foo'
  from ../test.rb:11:in `<main>'

Conversely:

def foo(&block)
  block.call do |x|
    puts x
  end
end

foo {
  yield 14
}
$ ruby ../test.rb 
../test.rb:8:in `block in <main>': no block given (yield) (LocalJumpError)
    from ../test.rb:2:in `call'
    from ../test.rb:2:in `foo'
    from ../test.rb:7:in `<main>'
$ jt run ../test.rb 
14

It looks like this is to do with what version of the method we use when something is a method and when it's a block - we store multiple versions of methods depending on how they're used.

@chrisseaton
Copy link
Contributor

Fixed in 06c5d29

@enebo enebo added this to the Invalid or Duplicate milestone Dec 7, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants