default arguments & define_method:  JRuby ~ MRI mismatch
--------------------------------------------------------

                 Key: JRUBY-4657
                 URL: http://jira.codehaus.org/browse/JRUBY-4657
             Project: JRuby
          Issue Type: Bug
          Components: Ruby 1.8.7, Ruby 1.9
    Affects Versions: JRuby 1.4, JRuby 1.3, JRuby 1.5
         Environment: Debian Sqeeze, Java 5, Java 6
            Reporter: Gergely Nagy
            Priority: Minor


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).


{code:title=testie.rb|borderStyle=solid}
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)

{code}

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.

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: 
http://jira.codehaus.org/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email


Reply via email to