Details
-
Type:
Bug
-
Status:
Closed
-
Priority:
Minor
-
Resolution: Won't Fix
-
Affects Version/s: JRuby 1.3, JRuby 1.4, JRuby 1.5
-
Fix Version/s: None
-
Component/s: Ruby 1.8.7, Ruby 1.9.2
-
Labels:None
-
Environment:Debian Sqeeze, Java 5, Java 6
-
Testcase included:yes
-
Number of attachments :
Description
1. Have a method in a class with default arguments,
2. subclass this,
3. overriding the method with 'define_method' with no block arguments.
Problem: calling 'super' won't propagate arguments to the superclass.
Workaround: add an (unused) block argument now the super method argument will be passed correctly.
Tried this with JRuby 1.3, 1.4 and trunk, with both --1.8 and --1.9.
MRI 1.8.7 is fine with this (you don't have to declare unused block arguments to get it working consistently).
class A def f(x = :default) warn "#{self.class} super f(#{x})" x end end class B < A define_method :f do |x| super end end class C < A define_method :f do # no block arg super end end B.new.f(:override) #### -> :override C.new.f(:override) #### -> :default (JRuby), :override (MRI)
Note: as Vladimir pointed out, MRI 1.9.x reports this as error (block arity must match the invocation).
That's probably the more correct behaviour in general.
However, because of a difference on how 1.9 and 1.8 handles blocks arity, I think JRuby should support both:
- in 1.8 mode it should return :override for both invocations.
- in 1.9 mode it should complain as MRI does.