Skip to content

Jitted blocks do not scope evals properly #3368

@headius

Description

@headius

This is the cause of the current TestMarshal failures.

Reduced case follows.

blah.rb:

class X
  def initialize
    p :here
  end
  Class.new { eval 'def initialize; p :there; end' }
end

Command line and bug (:there should be :here):

$ jruby -Xjit.threshold=0 -e "load './blah.rb'; X.new"
2015-10-03T02:18:02.890-05:00: Ruby: done compiling target script: -e
2015-10-03T02:18:02.910-05:00: JITCompiler: done jitting:<block> at /Users/headius/projects/jruby/blah.rb:4
2015-10-03T02:18:02.916-05:00: JITCompiler: done jitting:X.X.initialize at (eval):0
:there

The problem here seems to be that when a block is jitted, it's not framing itself or rooting the eval properly. I have not investigated further than that, but obviously the eval'ed def initialize is going into the surrounding class X rather than into the Class.new that launched the block.

This breaks TestMarshal because of test_marshal.rb:263-266.

  classISO8859_1 = Class.new do
    attr_accessor "r\xe9sum\xe9".force_encoding(iso_8859_1)
    eval("def initialize(x); @r\xe9sum\xe9 = x; end".force_encoding(iso_8859_1))
  end

This initialize becomes TestMarshal's initialize, As a result, the name of the test passed into TestMarshal.new (as part of test suite initialization) never reaches the TestCase superclass, and the __name__ remains nil. That's the source of the errors we see in the test run:

[1/1] TestMarshal#test_symbol2 = 0.17 s
  1) Error:
TestMarshal#:
TypeError: no implicit conversion of nil into String
    /Users/headius/projects/jruby/test/mri/lib/test/unit/testcase.rb:17:in `run'
    org/jruby/RubyArray.java:2300:in `map'
    /Users/headius/projects/jruby/test/mri/lib/test/unit.rb:682:in `block in _run_suites'
    org/jruby/RubyArray.java:1560:in `each'
    /Users/headius/projects/jruby/test/mri/lib/test/unit.rb:680:in `_run_suites'
    org/jruby/RubyArray.java:1560:in `each'
    /Users/headius/projects/jruby/test/mri/lib/test/unit.rb:31:in `run'
    /Users/headius/projects/jruby/test/mri/lib/test/unit.rb:799:in `run'
    /Users/headius/projects/jruby/test/mri/lib/test/unit.rb:859:in `run'
    /Users/headius/projects/jruby/test/mri/lib/test/unit.rb:863:in `run'
    test/mri/runner.rb:41:in `<top>'

Note that the method name in the error report is missing.

cc @enebo

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions