ruby-core@ruby-lang.org archive (unofficial mirror)
 help / color / mirror / Atom feed
* [ruby-core:115430] [Ruby master Bug#20012] Fix keyword splat passing as regular argument
@ 2023-11-21  4:23 jeremyevans0 (Jeremy Evans) via ruby-core
  2023-11-21  7:48 ` [ruby-core:115431] " matz (Yukihiro Matsumoto) via ruby-core
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: jeremyevans0 (Jeremy Evans) via ruby-core @ 2023-11-21  4:23 UTC (permalink / raw
  To: ruby-core; +Cc: jeremyevans0 (Jeremy Evans)

Issue #20012 has been reported by jeremyevans0 (Jeremy Evans).

----------------------------------------
Bug #20012: Fix keyword splat passing as regular argument
https://bugs.ruby-lang.org/issues/20012

* Author: jeremyevans0 (Jeremy Evans)
* Status: Open
* Priority: Normal
* ruby -v: ruby 3.3.0dev (2023-11-12 master 60e19a0b5f) [x86_64-openbsd]
* Backport: 3.0: UNKNOWN, 3.1: UNKNOWN, 3.2: UNKNOWN
----------------------------------------
Since Ruby 3.0, Ruby has passed a keyword splat as a regular argument in the case of a call to a Ruby method where the method does not accept keyword arguments, if the method call does not contain an argument splat:

```ruby
def self.f(obj) obj end
def self.fs(*obj) obj[0] end
h = {a: 1}
f(**h).equal?(h)  # Before: true; After: false
fs(**h).equal?(h) # Before: true; After: false

a = []
f(*a, **h).equal?(h)  # Before and After: false
fs(*a, **h).equal?(h) # Before and After: false
```

The fact that the behavior differs when passing an empty argument splat makes it obvious that something is not working the way it is intended.  The fact that the hash is copied for C methods also makes it obvious.  Ruby 2 always copied the keyword splat hash, and I think that is the expected behavior in Ruby 3.

This bug is because of a missed check in setup_parameters_complex. If the keyword splat passed is not mutable, then it points to an existing object and not a new object, and therefore it must be copied.

I did not bisect to find the commit that introduced the problem, but this seems likely to be something I introduced during keyword argument separation.  I'm surprised that this has not been filed as a bug sooner.  Maybe it just rarely comes up in practice, and I only discovered it recently. Possibly, other developers that may have discovered this may have decided against submitting this as an issue, as we have had specs for two years that give the impression that the broken behavior was expected.

I've submitted a pull request to fix this: https://github.com/ruby/ruby/pull/8970



-- 
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/postorius/lists/ruby-core.ml.ruby-lang.org/

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [ruby-core:115431] [Ruby master Bug#20012] Fix keyword splat passing as regular argument
  2023-11-21  4:23 [ruby-core:115430] [Ruby master Bug#20012] Fix keyword splat passing as regular argument jeremyevans0 (Jeremy Evans) via ruby-core
@ 2023-11-21  7:48 ` matz (Yukihiro Matsumoto) via ruby-core
  2023-11-21 10:37 ` [ruby-core:115434] " byroot (Jean Boussier) via ruby-core
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: matz (Yukihiro Matsumoto) via ruby-core @ 2023-11-21  7:48 UTC (permalink / raw
  To: ruby-core; +Cc: matz (Yukihiro Matsumoto)

Issue #20012 has been updated by matz (Yukihiro Matsumoto).


 I am in favor of this change, but at the same time concerned about compatibility. I'd like to make sure there won't be any major problems before adopting it.

Matz.


----------------------------------------
Bug #20012: Fix keyword splat passing as regular argument
https://bugs.ruby-lang.org/issues/20012#change-105361

* Author: jeremyevans0 (Jeremy Evans)
* Status: Open
* Priority: Normal
* ruby -v: ruby 3.3.0dev (2023-11-12 master 60e19a0b5f) [x86_64-openbsd]
* Backport: 3.0: UNKNOWN, 3.1: UNKNOWN, 3.2: UNKNOWN
----------------------------------------
Since Ruby 3.0, Ruby has passed a keyword splat as a regular argument in the case of a call to a Ruby method where the method does not accept keyword arguments, if the method call does not contain an argument splat:

```ruby
def self.f(obj) obj end
def self.fs(*obj) obj[0] end
h = {a: 1}
f(**h).equal?(h)  # Before: true; After: false
fs(**h).equal?(h) # Before: true; After: false

a = []
f(*a, **h).equal?(h)  # Before and After: false
fs(*a, **h).equal?(h) # Before and After: false
```

The fact that the behavior differs when passing an empty argument splat makes it obvious that something is not working the way it is intended.  The fact that the hash is copied for C methods also makes it obvious.  Ruby 2 always copied the keyword splat hash, and I think that is the expected behavior in Ruby 3.

This bug is because of a missed check in setup_parameters_complex. If the keyword splat passed is not mutable, then it points to an existing object and not a new object, and therefore it must be copied.

I did not bisect to find the commit that introduced the problem, but this seems likely to be something I introduced during keyword argument separation.  I'm surprised that this has not been filed as a bug sooner.  Maybe it just rarely comes up in practice, and I only discovered it recently. Possibly, other developers that may have discovered this may have decided against submitting this as an issue, as we have had specs for two years that give the impression that the broken behavior was expected.

I've submitted a pull request to fix this: https://github.com/ruby/ruby/pull/8970



-- 
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/postorius/lists/ruby-core.ml.ruby-lang.org/

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [ruby-core:115434] [Ruby master Bug#20012] Fix keyword splat passing as regular argument
  2023-11-21  4:23 [ruby-core:115430] [Ruby master Bug#20012] Fix keyword splat passing as regular argument jeremyevans0 (Jeremy Evans) via ruby-core
  2023-11-21  7:48 ` [ruby-core:115431] " matz (Yukihiro Matsumoto) via ruby-core
@ 2023-11-21 10:37 ` byroot (Jean Boussier) via ruby-core
  2023-11-21 18:27 ` [ruby-core:115441] " jeremyevans0 (Jeremy Evans) via ruby-core
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: byroot (Jean Boussier) via ruby-core @ 2023-11-21 10:37 UTC (permalink / raw
  To: ruby-core; +Cc: byroot (Jean Boussier)

Issue #20012 has been updated by byroot (Jean Boussier).


I tried this on Shopify's monolith CI and it's breaking quite hard:

```ruby
      ATTRIBUTE_NAMES = T.let(
        [
          :currency,
          :description,
          :kind,
          :price,
          :reasons,
          :receipt,
          :shipping_service_charge_id,
          :shipping_service_label_id,
          :origin_address,
        ].freeze,
        T::Array[Symbol]
      )

      T.unsafe(self).validates(*ATTRIBUTE_NAMES, presence: true) # here
```

```
 `<class:Payload>': can't modify frozen Array: [:currency, :description, :kind, :price, :reasons, :receipt, :shipping_service_charge_id, :shipping_service_label_id, :origin_address] (FrozenError)
	from /app/components/delivery/app/services/shipping/adjustment_creator/payload.rb:6:in `<class:AdjustmentCreator>'
	from /app/components/delivery/app/services/shipping/adjustment_creator/payload.rb:5:in `<module:Shipping>'
	from /app/components/delivery/app/services/shipping/adjustment_creator/payload.rb:4:in `<main>'
```

----------------------------------------
Bug #20012: Fix keyword splat passing as regular argument
https://bugs.ruby-lang.org/issues/20012#change-105365

* Author: jeremyevans0 (Jeremy Evans)
* Status: Open
* Priority: Normal
* ruby -v: ruby 3.3.0dev (2023-11-12 master 60e19a0b5f) [x86_64-openbsd]
* Backport: 3.0: UNKNOWN, 3.1: UNKNOWN, 3.2: UNKNOWN
----------------------------------------
Since Ruby 3.0, Ruby has passed a keyword splat as a regular argument in the case of a call to a Ruby method where the method does not accept keyword arguments, if the method call does not contain an argument splat:

```ruby
def self.f(obj) obj end
def self.fs(*obj) obj[0] end
h = {a: 1}
f(**h).equal?(h)  # Before: true; After: false
fs(**h).equal?(h) # Before: true; After: false

a = []
f(*a, **h).equal?(h)  # Before and After: false
fs(*a, **h).equal?(h) # Before and After: false
```

The fact that the behavior differs when passing an empty argument splat makes it obvious that something is not working the way it is intended.  The fact that the hash is copied for C methods also makes it obvious.  Ruby 2 always copied the keyword splat hash, and I think that is the expected behavior in Ruby 3.

This bug is because of a missed check in setup_parameters_complex. If the keyword splat passed is not mutable, then it points to an existing object and not a new object, and therefore it must be copied.

I did not bisect to find the commit that introduced the problem, but this seems likely to be something I introduced during keyword argument separation.  I'm surprised that this has not been filed as a bug sooner.  Maybe it just rarely comes up in practice, and I only discovered it recently. Possibly, other developers that may have discovered this may have decided against submitting this as an issue, as we have had specs for two years that give the impression that the broken behavior was expected.

I've submitted a pull request to fix this: https://github.com/ruby/ruby/pull/8970



-- 
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/postorius/lists/ruby-core.ml.ruby-lang.org/

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [ruby-core:115441] [Ruby master Bug#20012] Fix keyword splat passing as regular argument
  2023-11-21  4:23 [ruby-core:115430] [Ruby master Bug#20012] Fix keyword splat passing as regular argument jeremyevans0 (Jeremy Evans) via ruby-core
  2023-11-21  7:48 ` [ruby-core:115431] " matz (Yukihiro Matsumoto) via ruby-core
  2023-11-21 10:37 ` [ruby-core:115434] " byroot (Jean Boussier) via ruby-core
@ 2023-11-21 18:27 ` jeremyevans0 (Jeremy Evans) via ruby-core
  2023-12-07  9:59 ` [ruby-core:115638] " mame (Yusuke Endoh) via ruby-core
  2023-12-08  0:34 ` [ruby-core:115651] " jeremyevans0 (Jeremy Evans) via ruby-core
  4 siblings, 0 replies; 6+ messages in thread
From: jeremyevans0 (Jeremy Evans) via ruby-core @ 2023-11-21 18:27 UTC (permalink / raw
  To: ruby-core; +Cc: jeremyevans0 (Jeremy Evans)

Issue #20012 has been updated by jeremyevans0 (Jeremy Evans).


matz (Yukihiro Matsumoto) wrote in #note-1:
> I am in favor of this change, but at the same time concerned about compatibility. I'd like to make sure there won't be any major problems before adopting it.

Would you prefer we merge it soon and have the fix in Ruby 3.3, or should we wait until after Ruby 3.3 and put the fix in Ruby 3.4, which will allow for more testing time before release?


----------------------------------------
Bug #20012: Fix keyword splat passing as regular argument
https://bugs.ruby-lang.org/issues/20012#change-105374

* Author: jeremyevans0 (Jeremy Evans)
* Status: Open
* Priority: Normal
* ruby -v: ruby 3.3.0dev (2023-11-12 master 60e19a0b5f) [x86_64-openbsd]
* Backport: 3.0: UNKNOWN, 3.1: UNKNOWN, 3.2: UNKNOWN
----------------------------------------
Since Ruby 3.0, Ruby has passed a keyword splat as a regular argument in the case of a call to a Ruby method where the method does not accept keyword arguments, if the method call does not contain an argument splat:

```ruby
def self.f(obj) obj end
def self.fs(*obj) obj[0] end
h = {a: 1}
f(**h).equal?(h)  # Before: true; After: false
fs(**h).equal?(h) # Before: true; After: false

a = []
f(*a, **h).equal?(h)  # Before and After: false
fs(*a, **h).equal?(h) # Before and After: false
```

The fact that the behavior differs when passing an empty argument splat makes it obvious that something is not working the way it is intended.  The fact that the hash is copied for C methods also makes it obvious.  Ruby 2 always copied the keyword splat hash, and I think that is the expected behavior in Ruby 3.

This bug is because of a missed check in setup_parameters_complex. If the keyword splat passed is not mutable, then it points to an existing object and not a new object, and therefore it must be copied.

I did not bisect to find the commit that introduced the problem, but this seems likely to be something I introduced during keyword argument separation.  I'm surprised that this has not been filed as a bug sooner.  Maybe it just rarely comes up in practice, and I only discovered it recently. Possibly, other developers that may have discovered this may have decided against submitting this as an issue, as we have had specs for two years that give the impression that the broken behavior was expected.

I've submitted a pull request to fix this: https://github.com/ruby/ruby/pull/8970



-- 
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/postorius/lists/ruby-core.ml.ruby-lang.org/

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [ruby-core:115638] [Ruby master Bug#20012] Fix keyword splat passing as regular argument
  2023-11-21  4:23 [ruby-core:115430] [Ruby master Bug#20012] Fix keyword splat passing as regular argument jeremyevans0 (Jeremy Evans) via ruby-core
                   ` (2 preceding siblings ...)
  2023-11-21 18:27 ` [ruby-core:115441] " jeremyevans0 (Jeremy Evans) via ruby-core
@ 2023-12-07  9:59 ` mame (Yusuke Endoh) via ruby-core
  2023-12-08  0:34 ` [ruby-core:115651] " jeremyevans0 (Jeremy Evans) via ruby-core
  4 siblings, 0 replies; 6+ messages in thread
From: mame (Yusuke Endoh) via ruby-core @ 2023-12-07  9:59 UTC (permalink / raw
  To: ruby-core; +Cc: mame (Yusuke Endoh)

Issue #20012 has been updated by mame (Yusuke Endoh).


@jeremyevans0 In today's dev meeting, @matz said it should be fixed soon, so let's merge it. If someone complains it, we may reconsider.

----------------------------------------
Bug #20012: Fix keyword splat passing as regular argument
https://bugs.ruby-lang.org/issues/20012#change-105572

* Author: jeremyevans0 (Jeremy Evans)
* Status: Open
* Priority: Normal
* ruby -v: ruby 3.3.0dev (2023-11-12 master 60e19a0b5f) [x86_64-openbsd]
* Backport: 3.0: UNKNOWN, 3.1: UNKNOWN, 3.2: UNKNOWN
----------------------------------------
Since Ruby 3.0, Ruby has passed a keyword splat as a regular argument in the case of a call to a Ruby method where the method does not accept keyword arguments, if the method call does not contain an argument splat:

```ruby
def self.f(obj) obj end
def self.fs(*obj) obj[0] end
h = {a: 1}
f(**h).equal?(h)  # Before: true; After: false
fs(**h).equal?(h) # Before: true; After: false

a = []
f(*a, **h).equal?(h)  # Before and After: false
fs(*a, **h).equal?(h) # Before and After: false
```

The fact that the behavior differs when passing an empty argument splat makes it obvious that something is not working the way it is intended.  The fact that the hash is copied for C methods also makes it obvious.  Ruby 2 always copied the keyword splat hash, and I think that is the expected behavior in Ruby 3.

This bug is because of a missed check in setup_parameters_complex. If the keyword splat passed is not mutable, then it points to an existing object and not a new object, and therefore it must be copied.

I did not bisect to find the commit that introduced the problem, but this seems likely to be something I introduced during keyword argument separation.  I'm surprised that this has not been filed as a bug sooner.  Maybe it just rarely comes up in practice, and I only discovered it recently. Possibly, other developers that may have discovered this may have decided against submitting this as an issue, as we have had specs for two years that give the impression that the broken behavior was expected.

I've submitted a pull request to fix this: https://github.com/ruby/ruby/pull/8970



-- 
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/postorius/lists/ruby-core.ml.ruby-lang.org/

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [ruby-core:115651] [Ruby master Bug#20012] Fix keyword splat passing as regular argument
  2023-11-21  4:23 [ruby-core:115430] [Ruby master Bug#20012] Fix keyword splat passing as regular argument jeremyevans0 (Jeremy Evans) via ruby-core
                   ` (3 preceding siblings ...)
  2023-12-07  9:59 ` [ruby-core:115638] " mame (Yusuke Endoh) via ruby-core
@ 2023-12-08  0:34 ` jeremyevans0 (Jeremy Evans) via ruby-core
  4 siblings, 0 replies; 6+ messages in thread
From: jeremyevans0 (Jeremy Evans) via ruby-core @ 2023-12-08  0:34 UTC (permalink / raw
  To: ruby-core; +Cc: jeremyevans0 (Jeremy Evans)

Issue #20012 has been updated by jeremyevans0 (Jeremy Evans).

Status changed from Open to Closed

Fixed by commit:ca204a20231f1ecabf5a7343aec49c3ea1bac90a

----------------------------------------
Bug #20012: Fix keyword splat passing as regular argument
https://bugs.ruby-lang.org/issues/20012#change-105587

* Author: jeremyevans0 (Jeremy Evans)
* Status: Closed
* Priority: Normal
* ruby -v: ruby 3.3.0dev (2023-11-12 master 60e19a0b5f) [x86_64-openbsd]
* Backport: 3.0: UNKNOWN, 3.1: UNKNOWN, 3.2: UNKNOWN
----------------------------------------
Since Ruby 3.0, Ruby has passed a keyword splat as a regular argument in the case of a call to a Ruby method where the method does not accept keyword arguments, if the method call does not contain an argument splat:

```ruby
def self.f(obj) obj end
def self.fs(*obj) obj[0] end
h = {a: 1}
f(**h).equal?(h)  # Before: true; After: false
fs(**h).equal?(h) # Before: true; After: false

a = []
f(*a, **h).equal?(h)  # Before and After: false
fs(*a, **h).equal?(h) # Before and After: false
```

The fact that the behavior differs when passing an empty argument splat makes it obvious that something is not working the way it is intended.  The fact that the hash is copied for C methods also makes it obvious.  Ruby 2 always copied the keyword splat hash, and I think that is the expected behavior in Ruby 3.

This bug is because of a missed check in setup_parameters_complex. If the keyword splat passed is not mutable, then it points to an existing object and not a new object, and therefore it must be copied.

I did not bisect to find the commit that introduced the problem, but this seems likely to be something I introduced during keyword argument separation.  I'm surprised that this has not been filed as a bug sooner.  Maybe it just rarely comes up in practice, and I only discovered it recently. Possibly, other developers that may have discovered this may have decided against submitting this as an issue, as we have had specs for two years that give the impression that the broken behavior was expected.

I've submitted a pull request to fix this: https://github.com/ruby/ruby/pull/8970



-- 
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/postorius/lists/ruby-core.ml.ruby-lang.org/

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2023-12-08  0:34 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-11-21  4:23 [ruby-core:115430] [Ruby master Bug#20012] Fix keyword splat passing as regular argument jeremyevans0 (Jeremy Evans) via ruby-core
2023-11-21  7:48 ` [ruby-core:115431] " matz (Yukihiro Matsumoto) via ruby-core
2023-11-21 10:37 ` [ruby-core:115434] " byroot (Jean Boussier) via ruby-core
2023-11-21 18:27 ` [ruby-core:115441] " jeremyevans0 (Jeremy Evans) via ruby-core
2023-12-07  9:59 ` [ruby-core:115638] " mame (Yusuke Endoh) via ruby-core
2023-12-08  0:34 ` [ruby-core:115651] " jeremyevans0 (Jeremy Evans) via ruby-core

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).