Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
yui-knk committed Apr 7, 2024
1 parent 9b4cf64 commit 8bb7cc0
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 6 deletions.
1 change: 0 additions & 1 deletion internal/parse.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ int rb_ruby_parser_end_seen_p(rb_parser_t *p);
int rb_ruby_parser_set_yydebug(rb_parser_t *p, int flag);
rb_parser_string_t *rb_str_to_parser_string(rb_parser_t *p, VALUE str);

void rb_parser_warn_duplicate_keys(struct parser_params *p, NODE *hash);
int rb_parser_dvar_defined_ref(struct parser_params*, ID, ID**);
ID rb_parser_internal_id(struct parser_params*);
VALUE rb_parser_node_case_when_optimizable_literal(struct parser_params *p, const NODE *const node);
Expand Down
8 changes: 3 additions & 5 deletions parse.y
Original file line number Diff line number Diff line change
Expand Up @@ -14872,7 +14872,6 @@ nd_type_st_key_enable_p(NODE *node)
}
}

#ifndef RIPPER
static VALUE
nd_value(struct parser_params *p, NODE *node)
{
Expand Down Expand Up @@ -14903,8 +14902,8 @@ nd_value(struct parser_params *p, NODE *node)
}
}

void
rb_parser_warn_duplicate_keys(struct parser_params *p, NODE *hash)
static void
warn_duplicate_keys(struct parser_params *p, NODE *hash)
{
/* See https://bugs.ruby-lang.org/issues/20331 for discussion about what is warned. */
st_table *literal_keys = st_init_table_with_size(&literal_type, RNODE_LIST(hash)->as.nd_alen / 2);
Expand Down Expand Up @@ -14934,12 +14933,11 @@ rb_parser_warn_duplicate_keys(struct parser_params *p, NODE *hash)
}
st_free_table(literal_keys);
}
#endif

static NODE *
new_hash(struct parser_params *p, NODE *hash, const YYLTYPE *loc)
{
if (hash) rb_parser_warn_duplicate_keys(p, hash);
if (hash) warn_duplicate_keys(p, hash);
return NEW_HASH(hash, loc);
}

Expand Down
6 changes: 6 additions & 0 deletions test/ripper/test_parser_events.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1686,6 +1686,12 @@ def test_warning_duplicated_when_clause
assert_equal([3], args)
end

def test_warning_duplicated_hash_keys
fmt, *args = warning("{ a: 1, a: 2 }")
assert_match(/duplicated 'when' clause/, fmt)
assert_equal([3], args)
end

def test_warn_cr_in_middle
fmt = nil
assert_warn("") {fmt, = warn("\r;")}
Expand Down

0 comments on commit 8bb7cc0

Please sign in to comment.