Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

I found a bug using the generated Csharp MergeFrom method #10327

Closed
cluo0618 opened this issue Jul 28, 2022 · 2 comments · Fixed by #10339
Closed

I found a bug using the generated Csharp MergeFrom method #10327

cluo0618 opened this issue Jul 28, 2022 · 2 comments · Fixed by #10339
Assignees

Comments

@cluo0618
Copy link

Hi
I found a bug using the generated Csharp MergeFrom method. If my data contains mapfield, mergefrom will add other mapfield directly. If there are duplicates, it will always report : ArgumentException: Key already exists in map. I think the merge of the map should be changed to containskey and then directly replace the element.

`public void MergeFrom(LineComponent other) {

  if (other == null) {
    return;
  }
  if (other.target_ != null) {
    if (target_ == null) {
      Target = new global::Protocol.LineInfoComponent(); 
    }
    Target.MergeFrom(other.Target);
  }
  lines_.Add(other.lines_);
  _unknownFields = pb::UnknownFieldSet.MergeFrom(_unknownFields, other._unknownFields);
}`

this lines is a mapfield type,using add directly on the opposite mapfield type will always report an error.

@cluo0618 cluo0618 added the untriaged auto added to all issues by default when created. label Jul 28, 2022
@amanda-tarafa amanda-tarafa added question c# P2 and removed untriaged auto added to all issues by default when created. P2 labels Jul 28, 2022
@jskeet jskeet self-assigned this Aug 1, 2022
@jskeet
Copy link
Contributor

jskeet commented Aug 1, 2022

Right, it looks like we should be using a specific merge method for a MapField<,>. The language guide specifically says:

When parsing from the wire or when merging, if there are duplicate map keys the last key seen is used. When parsing a map from text format, parsing may fail if there are duplicate keys.

I'll come up with a unit test to reproduce this, then fix it. It's likely to need both a generator and a support library change.

@cluo0618
Copy link
Author

cluo0618 commented Aug 2, 2022

thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants