summaryrefslogtreecommitdiff
path: root/struct.c
diff options
context:
space:
mode:
authorJeremy Evans <code@jeremyevans.net>2023-03-23 13:44:04 -0700
committerJeremy Evans <code@jeremyevans.net>2023-04-24 07:37:20 -0700
commitf8e7048348d022814736d0a7e49f2f2494db6a2f (patch)
treeeecca5b3e7fa827a81d71fe9cdfc6adc41b9afc9 /struct.c
parent73fc81199de5e567e38f7ea9067260eb6866cbf9 (diff)
downloadruby-f8e7048348d022814736d0a7e49f2f2494db6a2f.tar.gz
Allow anonymous memberless Struct
Previously, named memberless Structs were allowed, but anonymous memberless Structs were not. Fixes [Bug #19416]
Diffstat (limited to 'struct.c')
-rw-r--r--struct.c11
1 files changed, 4 insertions, 7 deletions
diff --git a/struct.c b/struct.c
index 819f1a8258..7a8a642021 100644
--- a/struct.c
+++ b/struct.c
@@ -637,17 +637,14 @@ rb_struct_define_under(VALUE outer, const char *name, ...)
static VALUE
rb_struct_s_def(int argc, VALUE *argv, VALUE klass)
{
- VALUE name, rest, keyword_init = Qnil;
+ VALUE name = Qnil, rest, keyword_init = Qnil;
long i;
VALUE st;
VALUE opt;
- argc = rb_scan_args(argc, argv, "1*:", NULL, NULL, &opt);
- name = argv[0];
- if (SYMBOL_P(name)) {
- name = Qnil;
- }
- else {
+ argc = rb_scan_args(argc, argv, "0*:", NULL, &opt);
+ if (argc >= 1 && !SYMBOL_P(argv[0])) {
+ name = argv[0];
--argc;
++argv;
}