-
-
Notifications
You must be signed in to change notification settings - Fork 925
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Kernel#proc with no arguments inside a method, fails with ArgumentError: tried to create Proc object without a block #3915
Comments
I have a similar issue, which I got narrowed down to the following System info: java version "1.8.0_60" jruby versions (both versions reproduce the issue) Example code: # this method somehow gets mangled in compilation?
def failingMethod
::Proc.new.call
end
# if this is used instead, everything compiles well!
def workingMethod
Proc.new.call
end
some_var = "it fails!"
failingMethod do
some_var = "it works!"
end
# should print "it works!"
puts some_var When run, the above code produces the output:
If the same ruby file is run with compilation turned off, everything works fine. |
This isn't something we're likely to fix. It works in MRI only because of the way MRI is implemented. The current call's passed block just happens to be available when calling proc, and proc just happens to not care where the block comes from. Similar behavior happens for Proc.new, but both behaviors are discouraged and may go away in future versions of Ruby. FWIW, Proc.new does currently work only because we make a special case for it in our compiler. Your best bet short term is to either use Proc.new or capture the block in the method signature with |
I was kind-of expecting something like that given how "magic" the whole thing feels. Thanks for telling us that we shouldn't hold our breath, it's appreciated. So, I'll slowly remove 'proc' from my projects ... It's not as if there was many of them. |
@doudou Thanks for understanding! I hope some day CRuby makes it official that these forms are not expected to work, since they're pretty weird anyway. |
jruby 9.0.5.0 and 9.1.0.0
OS:
gentoo linux kernel 4.1.15, 64 bit kernel, 32-bit userland
gentoo linux kernel 4.1.15, 64 bit kernel, 64-bit userland
~ $ java -version
java version "1.8.0_77"
Java(TM) SE Runtime Environment (build 1.8.0_77-b03)
Java HotSpot(TM) 64-Bit Server VM (build 25.77-b03, mixed mode)
The text was updated successfully, but these errors were encountered: