Passing block explicitly to superclass method fails #1237

Closed
wied03 opened this Issue Dec 9, 2015 · 5 comments

Projects

None yet

2 participants

@wied03
Contributor
wied03 commented Dec 9, 2015

At one point this worked (or maybe was not fully working) in Opal 0.9 but now it complains:

class SuperClass
  def add_stub(&block)
    puts 'super method, calling block'
    block.call
  end
end

class InheritingClass < SuperClass
  def add_stub(*args, &block)
    super(*args, &block)
  end
end

InheritingClass.new.add_stub do
  puts 'block ran'
end

Runs OK in MRI. It does not happen with a standalone method nor does it happen when 1 method calls another in the same fashion, just when calling the superclass' method. This also causes arity checking to break.

MRI:

super method, calling block
block ran

Opal:

super method, calling block

/tmp/opal-nodejs-runner-20151209-19233-13hhbbd:4249
      throw exception;
            ^
call: undefined method `call' for nil
    at OpalClass.Opal.defs.self [as $new] (/tmp/opal-nodejs-runner-20151209-19233-13hhbbd:4466:15)
    at NilClass.Opal.defn.TMP_1 (/tmp/opal-nodejs-runner-20151209-19233-13hhbbd:3028:54)
    at NilClass.method_missing_stub [as $call] (/tmp/opal-nodejs-runner-20151209-19233-13hhbbd:888:35)
    at $InheritingClass.Opal.defn.TMP_1 (/tmp/opal-nodejs-runner-20151209-19233-13hhbbd:19037:20)
    at $InheritingClass.Opal.defn.TMP_2 [as $add_stub] (/tmp/opal-nodejs-runner-20151209-19233-13hhbbd:19056:72)
    at Opal.dynamic_require_severity (/tmp/opal-nodejs-runner-20151209-19233-13hhbbd:19061:66)
    at Object.<anonymous> (/tmp/opal-nodejs-runner-20151209-19233-13hhbbd:19062:3)
    at Module._compile (module.js:456:26)
    at Object.Module._extensions..js (module.js:474:10)
    at Module.load (module.js:356:32)
@wied03 wied03 referenced this issue in opal/opal-rspec Dec 9, 2015
Closed

Get working with arity checking enabled #40

7 of 12 tasks complete
@elia
Member
elia commented Dec 9, 2015

the number -4 is right (confirmed on cruby) so the problem must reside in the check:

https://github.com/opal/opal/blob/3d5f8d32a75f56d8a5d36e298060dad6db7c5be3/lib/opal/nodes/def.rb#L238-L267

@wied03
Contributor
wied03 commented Dec 9, 2015

Looks like in the superclass case, the block isn't in TMP_1.$$p, it's the last argument in arguments, which causes arguments to be of length 5 instead of the 4 it's expecting

@wied03
Contributor
wied03 commented Dec 9, 2015

In a way, this has nothing to do with arity checking. If I disable arity checking, then the code fails because block in the add_stub method is nil

@elia
Member
elia commented Dec 9, 2015

So it's more like the arity check message can be improved…

@wied03
Contributor
wied03 commented Dec 9, 2015

Maybe. The bigger problem is the block thing. This reminds me of #1132.

@wied03 wied03 changed the title from Arity Checking (Regression?) to Passing block explicitly to superclass method fails Dec 9, 2015
@wied03 wied03 added a commit to wied03/opal that referenced this issue Feb 29, 2016
@wied03 wied03 Fix #1237 by focusing the runtime method solely on finding the functi…
…on, then alter the compiler to cover missing functionality use the existing call node to avoid duplicating logic.
1b76d4b
@elia elia closed this in #1367 Feb 29, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment