Project

General

Profile

Actions

Bug #2600

closed

block.callの中でsuperできない

Added by kou (Kouhei Sutou) over 14 years ago. Updated almost 13 years ago.

Status:
Closed
Target version:
ruby -v:
1.8
[ruby-dev:40059]

Description

=begin
須藤です。

r25975の変更

  • eval.c (proc_invoke): unbound block created by define_method
    cannot call super. [ruby-core:26984]

から、以下のようにすると

NoMethodError: super called outside of method

という例外が発生するようになりました。

class Parent
def run
:parent_run
end
end

class Child < Parent
def run
callback do
super
end
end

 def callback(&block)
   block.call
 end

end

Child.new.run # -> 例外

Child#callbackの中のblock.callをyieldにすると例外は起きなく
なります。

SubjectにBugをつけてしまったのですが、そもそもこれはBugではな
く意図した変更なのでしょうか?

とりあえず、テストケースは添付しておきます。

余談ですが、この間リリースされたRuby 1.8.7にもこの変更が入っ
ていたため、Rabbitが動かなくなり、この違いに気づきました。

Index: test/ruby/test_super.rb

--- test/ruby/test_super.rb (revision 26302)
+++ test/ruby/test_super.rb (working copy)
@@ -149,4 +149,26 @@
c = C.new
assert_equal([c, "#{C.to_s}::m"], c.m, bug2419)
end
+

  • class Parent
  • def run
  •  :parent_run
    
  • end
  • end
  • class Child < Parent
  • def run
  •  callback do
    
  •    super
    
  •  end
    
  • end
  • def callback(&block)
  •  block.call
    
  • end
  • end
  • def test_super_in_block_call
  • assert_equal(:parent_run, Child.new.run)
  • end
    end
    =end

Related issues 1 (0 open1 closed)

Is duplicate of Ruby 1.8 - Bug #2537: 継承クラスにて、ブロック内にてsuperを呼ぶと、super called outside of method (NoMethodError)が発生するClosednobu (Nobuyoshi Nakada)12/28/2009Actions
Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0