From: "Eregon (Benoit Daloze) via ruby-core" Date: 2024-08-01T10:27:17+00:00 Subject: [ruby-core:118771] [Ruby master Bug#20640] Evaluation Order Issue in f(**h, &h.delete(key)) Issue #20640 has been updated by Eregon (Benoit Daloze). IMO this kind of issue is not worth fixing, creating extra copies for this seems clearly not worth it (in perf hit vs very minimal gain). It is a bug of the user code to mutate arguments while passing them, the user code should be fixed to not do that. IOW the examples above make no sense and are unclear at best, relying on any specific semantics there is extremely brittle, and there is no value to do this in the first place anyway. ---------------------------------------- Bug #20640: Evaluation Order Issue in f(**h, &h.delete(key)) https://bugs.ruby-lang.org/issues/20640#change-109323 * Author: jeremyevans0 (Jeremy Evans) * Status: Open * Assignee: jeremyevans0 (Jeremy Evans) * Backport: 3.1: UNKNOWN, 3.2: UNKNOWN, 3.3: UNKNOWN ---------------------------------------- Since Ruby 3.0, there is an evaluation order issue when passing a single keyword splat and a block pass expression that modifies the keyword splat: ```ruby def f(*a, **kw) kw[:a].class end h = {a: ->{}} f(**h, &h.delete(:a)) # Ruby 2.0 - 2.7: Proc # Ruby 3.0 - 3.4: NilClass ``` For single keyword splats followed by positional argument splats, this has been an issue since 3.3: ```ruby def f(*a, **kw) kw[:a].class end h = {a: ->{}} a = [] f(*a, **h, &h.delete(:a)) # Ruby 2.0 - 3.2: Proc # Ruby 3.3 - 3.4: NilClass ``` Ruby handles these issues for positional splats, duplicating the splatted array before evaluating post, keyword, or block argument expressions: ```ruby f(*a, a.pop) # post argument f(*a, **a.pop) # keyword splat argument f(*a, a: a.pop) # keyword argument f(*a, &a.pop) # block argument ``` So it should handle the case for a keyword splat that could potentially be modified by block argument expression. I'll submit a pull request shortly to fix this issue. -- https://bugs.ruby-lang.org/ ______________________________________________ ruby-core mailing list -- ruby-core@ml.ruby-lang.org To unsubscribe send an email to ruby-core-leave@ml.ruby-lang.org ruby-core info -- https://ml.ruby-lang.org/mailman3/lists/ruby-core.ml.ruby-lang.org/