We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
When using a splat for block arguments with Proc.new, a tuple isn't created. Just the first block argument is assigned.
Proc.new
For example:
add = Proc(Int32, Int32, Int32).new do |*args| args.sum end puts add.call(1, 2)
results in:
Error: undefined method 'sum' for Int32
Only the first argument is picked up and assigned to args. It is not a tuple.
args
A more practical example is wrapping a proc where the arguments are unknown.
def wrap(proc : P) : P forall P P.new do |*args| puts "Before" value = proc.call(*args) puts "After" value end end proc = ->(x : Int32) { puts x } wrapped = wrap(proc) wrapped.call(42)
produces:
Error: argument to splat must be a tuple, not Int32
I've tried this in Crystal 1.14 and 1.15.
Related: #10242 There's something specific about Proc.new that causes this to fail.
The text was updated successfully, but these errors were encountered:
Proc.new isn't anything special, it just captures a block.
Reduced:
def capture(&block : Proc(Int32, Int32, Int32)) block end capture do |*args| args.sum # Error: undefined method 'sum' for Int32 end
It seems the parser completely ignores the *. This should rather be a parser error. Or it should work as expected, which I believe would be feasible.
*
Sorry, something went wrong.
No branches or pull requests
When using a splat for block arguments with
Proc.new
, a tuple isn't created. Just the first block argument is assigned.For example:
results in:
Only the first argument is picked up and assigned to
args
. It is not a tuple.A more practical example is wrapping a proc where the arguments are unknown.
produces:
I've tried this in Crystal 1.14 and 1.15.
Related: #10242
There's something specific about
Proc.new
that causes this to fail.The text was updated successfully, but these errors were encountered: