From: ruby-core@... Date: 2018-09-14T18:04:13+00:00 Subject: [ruby-core:89018] [Ruby trunk Bug#15078] Hash splat of empty hash should not create a positional argument. Issue #15078 has been updated by marcandre (Marc-Andre Lafortune). mame (Yusuke Endoh) wrote: > > Akr-san said that it would be impossible to create a "perfect" semantics to satisfy all cases. I'm sorry if I sounded like I had a "complete" solution, since Akr-san is right, there is no such perfect semantics. Proof ``` # Let foo be some method of unknown signature # Forward bar to foo: def bar(*args, **opt, &b) foo(*args, **opt, &b) end # If forwarding works, we have: bar({}) === foo({}) bar() === foo() # But by definition above, we have bar({}) === foo(**{}) # Since args = [], opt = {} (at least in Ruby 2.x) bar() === foo(**{}) # Since args = [], opt = {} # So, for any `foo`, we would need foo() === foo({}) # Not necessarily true... ``` > In Ruby 2.X, he said that `**empty_hash` should be just ignored, and that `foo({}, **{})` should be always equal to `foo({})`, even if `def foo(opt=42, **kw)` receives `opt=42`. (However, matz showed reluctance to this behavior. So, the solution for this ticket is not decided yet.) I'm glad he and I agree on the fact that is should be ignored most of the time. It could also not be ignored for methods that accept keyword parameters, which I believe is more logical and closer to what Ruby 3.0 would do. > Also, akr-san and some committers agreed with my proposal of "real" keyword arguments to solve all the kind of design flaws. (Surprisingly, there was no committer there who was against my proposal, even though it breaks compatibility. Matz also looked positive, but he has not made the decision yet.) > It would be impossible to write a delegation code that works perfectly on both 2.X and 3.0, but it would work good enough on almost all practical cases, akr-san said. Please consider my "vote" as in favor of half your proposal, and strong opposition to the other half :-) > Akr-san and some committers said that a hash or keyword should be decided syntactically based on `=>` or `:`. I agree that it should be syntactical. We can still decide that `foo(:key => 1)` is a keyword argument though. I'm undecided about this. Only important thing is that `foo(some_var => 1)` should never be considered a keyword argument, even if `some_var` is a Symbol. ---------------------------------------- Bug #15078: Hash splat of empty hash should not create a positional argument. https://bugs.ruby-lang.org/issues/15078#change-74044 * Author: marcandre (Marc-Andre Lafortune) * Status: Open * Priority: Normal * Assignee: matz (Yukihiro Matsumoto) * Target version: * ruby -v: ruby 2.6.0dev (2018-08-27 trunk 64545) [x86_64-darwin15] * Backport: 2.3: UNKNOWN, 2.4: UNKNOWN, 2.5: UNKNOWN ---------------------------------------- Looks like #10856 is not completely fixed, but I can't reopen it ``` def foo(*args); args; end foo(**{}) # => [] foo(**Hash.new) # => [{}], should be [] ``` -- https://bugs.ruby-lang.org/ Unsubscribe: