Project

General

Profile

Bug #11784 ยป 0001-insns.def-opt_case_dispatch-check-Float-redefinition.patch

normalperson (Eric Wong), 12/07/2015 11:54 PM

View differences:

insns.def
1271 1271
	if (BASIC_OP_UNREDEFINED_P(BOP_EQQ,
1272 1272
				   SYMBOL_REDEFINED_OP_FLAG |
1273 1273
				   FIXNUM_REDEFINED_OP_FLAG |
1274
				   FLOAT_REDEFINED_OP_FLAG |
1274 1275
				   BIGNUM_REDEFINED_OP_FLAG |
1275 1276
				   STRING_REDEFINED_OP_FLAG)) {
1276 1277
	    st_data_t val;
test/ruby/test_optimization.rb
308 308
      assert_equal(false, "block".freeze)
309 309
    end;
310 310
  end
311

  
312
  def test_opt_case_dispatch
313
    code = <<-EOF
314
      case foo
315
      when "foo" then :foo
316
      when :sym then :sym
317
      when 6 then :fix
318
      when 0.1 then :float
319
      when 0xffffffffffffffff then :big
320
      else
321
        :nomatch
322
      end
323
    EOF
324
    check = {
325
      'foo' => :foo,
326
      :sym => :sym,
327
      6 => :fix,
328
      0.1 => :float,
329
      0xffffffffffffffff => :big,
330
    }
331
    iseq = RubyVM::InstructionSequence.compile(code)
332
    assert_match %r{\bopt_case_dispatch\b}, iseq.disasm
333
    check.each do |foo, expect|
334
      assert_equal expect, eval("foo = #{foo.inspect}\n#{code}")
335
    end
336
    assert_equal :nomatch, eval("foo = :blah\n#{code}")
337
    check.each do |foo, _|
338
      klass = foo.class.to_s
339
      assert_separately([], <<-"end;") # do
340
        class #{klass}
341
          undef ===
342
          def ===(*args)
343
            false
344
          end
345
        end
346
        foo = #{foo.inspect}
347
        ret = #{code}
348
        assert_equal :nomatch, ret, foo.inspect
349
      end;
350
    end
351
  end
311 352
end
312
-