mirror of
https://github.com/ruby/ruby.git
synced 2025-09-17 09:33:59 +02:00
merge revision(s) 77596fb7a9
: [Backport #16138]
Do not turn on keyword_init for Struct subclass if keyword hash is empty This was accidentally turned on because there was no checking for Qundef. Also, since only a single keyword is currently supported, simplify the rb_get_kwargs call. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_2_5@67866 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
77d84046c7
commit
2655e657e1
3 changed files with 10 additions and 8 deletions
12
struct.c
12
struct.c
|
@ -517,7 +517,7 @@ rb_struct_define_under(VALUE outer, const char *name, ...)
|
||||||
static VALUE
|
static VALUE
|
||||||
rb_struct_s_def(int argc, VALUE *argv, VALUE klass)
|
rb_struct_s_def(int argc, VALUE *argv, VALUE klass)
|
||||||
{
|
{
|
||||||
VALUE name, rest, keyword_init;
|
VALUE name, rest, keyword_init = Qfalse;
|
||||||
long i;
|
long i;
|
||||||
VALUE st;
|
VALUE st;
|
||||||
st_table *tbl;
|
st_table *tbl;
|
||||||
|
@ -533,18 +533,16 @@ rb_struct_s_def(int argc, VALUE *argv, VALUE klass)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (RB_TYPE_P(argv[argc-1], T_HASH)) {
|
if (RB_TYPE_P(argv[argc-1], T_HASH)) {
|
||||||
VALUE kwargs[1];
|
|
||||||
static ID keyword_ids[1];
|
static ID keyword_ids[1];
|
||||||
|
|
||||||
if (!keyword_ids[0]) {
|
if (!keyword_ids[0]) {
|
||||||
keyword_ids[0] = rb_intern("keyword_init");
|
keyword_ids[0] = rb_intern("keyword_init");
|
||||||
}
|
}
|
||||||
rb_get_kwargs(argv[argc-1], keyword_ids, 0, 1, kwargs);
|
rb_get_kwargs(argv[argc-1], keyword_ids, 0, 1, &keyword_init);
|
||||||
|
if (keyword_init == Qundef) {
|
||||||
|
keyword_init = Qfalse;
|
||||||
|
}
|
||||||
--argc;
|
--argc;
|
||||||
keyword_init = kwargs[0];
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
keyword_init = Qfalse;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
rest = rb_ident_hash_new();
|
rest = rb_ident_hash_new();
|
||||||
|
|
|
@ -92,6 +92,10 @@ module TestStruct
|
||||||
assert_equal([:utime, :stime, :cutime, :cstime], Process.times.members)
|
assert_equal([:utime, :stime, :cutime, :cstime], Process.times.members)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_struct_new_with_empty_hash
|
||||||
|
assert_equal({:a=>1}, Struct.new(:a, {}).new({:a=>1}).a)
|
||||||
|
end
|
||||||
|
|
||||||
def test_struct_new_with_keyword_init
|
def test_struct_new_with_keyword_init
|
||||||
@Struct.new("KeywordInitTrue", :a, :b, keyword_init: true)
|
@Struct.new("KeywordInitTrue", :a, :b, keyword_init: true)
|
||||||
@Struct.new("KeywordInitFalse", :a, :b, keyword_init: false)
|
@Struct.new("KeywordInitFalse", :a, :b, keyword_init: false)
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
#define RUBY_VERSION "2.5.8"
|
#define RUBY_VERSION "2.5.8"
|
||||||
#define RUBY_RELEASE_DATE "2020-03-31"
|
#define RUBY_RELEASE_DATE "2020-03-31"
|
||||||
#define RUBY_PATCHLEVEL 215
|
#define RUBY_PATCHLEVEL 216
|
||||||
|
|
||||||
#define RUBY_RELEASE_YEAR 2020
|
#define RUBY_RELEASE_YEAR 2020
|
||||||
#define RUBY_RELEASE_MONTH 3
|
#define RUBY_RELEASE_MONTH 3
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue