[#111472] [Ruby master Bug#19274] Error installing ruby 3.2.0 on RH 8 — "aalllop (Alberto Allegue) via ruby-core" <ruby-core@...>
Issue #19274 has been reported by aalllop (Alberto Allegue).
5 messages
2022/12/28
[#111508] Data support for versions before 3.2.0 — Eustáquio Rangel via ruby-core <ruby-core@...>
I was wondering that every piece of code (gems, etc) that use the new Data =
3 messages
2022/12/29
[ruby-core:111515] [Ruby master Bug#19278] Constructing subclasses of Data with positional arguments
From:
"sam.saffron (Sam Saffron) via ruby-core" <ruby-core@...>
Date:
2022-12-29 21:37:12 UTC
List:
ruby-core #111515
Issue #19278 has been updated by sam.saffron (Sam Saffron).
Just going to be a bit more explicit here about the problem for future travelers (I know I am repeating but this is the most succinct way imo to show the issue)...
```
Foo = Data.define :x
class Bar < Foo
def initialize(*args, **kwargs)
p args
p kwargs
end
end
Bar.new(1)
# []
# {:x=>1}
```
I am with tenderlove here, needing to reason about new -> initialize auto coercion is somewhat scary...
I know this is a bucket of compromises given where we are at, but couldn't this just work correctly without coercion?
``
class Foo
attr_reader :x
def initialize(*args, **kwargs)
raise ArgumentError if args.length > 0 && kwargs.length > 0
raise ArgumentError if args.length > 1 || kwargs.length > 1
raise ArgumentError if kwargs.length == 1 && !kwargs.key?(:x)
if args.length > 0
x = args[0]
else
x = kwargs[:x]
end
end
end
```
----------------------------------------
Bug #19278: Constructing subclasses of Data with positional arguments
https://bugs.ruby-lang.org/issues/19278#change-100883
* Author: tenderlovemaking (Aaron Patterson)
* Status: Feedback
* Priority: Normal
* ruby -v: ruby 3.2.0 (2022-12-25 revision a528908271) [arm64-darwin22]
* Backport: 2.7: UNKNOWN, 3.0: UNKNOWN, 3.1: UNKNOWN, 3.2: UNKNOWN
----------------------------------------
I'd expect both of the following subclasses to work, but the subclass that uses positional parameters raises an exception:
```ruby
Foo = Data.define
class Bar < Foo
def initialize foo:
p foo
end
end
class Baz < Foo
def initialize foo
p foo
end
end
Bar.new foo: 1 # Prints 1
Baz.new 1 # Raises ArgumentError
```
I'd expect the subclass that uses positional arguments to work.
--
https://bugs.ruby-lang.org/
______________________________________________
ruby-core mailing list -- [email protected]
To unsubscribe send an email to [email protected]
ruby-core info -- https://ml.ruby-lang.org/mailman3/postorius/lists/ruby-core.ml.ruby-lang.org/