Override Map.clone to use Map's dup method

Message and Repeated field override clone so that it uses the internal implementation of dup but Map is missing this and only implements dup.  This can lead to unexpected behavior since two out of three complex types behave correctly.
This commit is contained in:
alusco-scratch 2020-10-01 21:20:31 -07:00 committed by GitHub
parent 344f28d4a2
commit 00a7ea4de1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -827,6 +827,8 @@ void Map_register(VALUE module) {
rb_define_method(klass, "clear", Map_clear, 0);
rb_define_method(klass, "length", Map_length, 0);
rb_define_method(klass, "dup", Map_dup, 0);
// Also define #clone so that we don't inherit Object#clone.
rb_define_method(klass, "clone", Map_dup, 0);
rb_define_method(klass, "==", Map_eq, 1);
rb_define_method(klass, "hash", Map_hash, 0);
rb_define_method(klass, "to_h", Map_to_h, 0);