Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.Sign up
It is possible to duplicate key in map if I use struct's field #37682
What version of Go are you using (
Matches the behavior of
I hope we agree that the latter is fine and correctly does the overwrite.
I see the error generated by
But I see your side of the argument also. If the semantics of the constructor are defined to require uniqueness, then we should check that.
We could get rid of the duplicate key error, as that's backwards compatible. It's harder to change the language to allow the constructor to panic, as that's not backwards compatible. Such a change really needs to be worth the churn, and I'm not sure that's true here.
If we go this route (make duplicates panic), we should also change the semantics of other keyed constructors (slices and arrays). But those seem harder to do, e.g.