kotlin icon indicating copy to clipboard operation
kotlin copied to clipboard

KT-21392 Fix the description of `MutableMap.getOrPut()`

Open mnonnenmacher opened this issue 7 years ago • 6 comments

Make clear that the defaultValue is also called if the key is present in the map but the value is null.

See: KT-21392

If you like this change I can make another commit for getOrElse which has the same problem.

mnonnenmacher avatar Jun 07 '18 17:06 mnonnenmacher

Wouldn't the more appropriate fix be to change the implementation to match the documentation? As I believe the documented behavior also is the behavior most developers would expect.

sschuberth avatar Jun 07 '18 19:06 sschuberth

@sschuberth: Yes, fixing the implementation would be my preferred fix, too, but I had doubts if it would be accepted as it is a potentially breaking change.

mnonnenmacher avatar Jun 07 '18 19:06 mnonnenmacher

In this case, I wouldn't regard it as a breaking change (i.e. you're not changing docs & implementation to behave differently than before), but a bug fix to make the implementation match the documentation (and desired behavior).

sschuberth avatar Jun 07 '18 20:06 sschuberth

This surprised me today! Good thing I usually read implementations and not just docs...

glasser avatar Feb 04 '20 18:02 glasser

Any news about this? This has been open for over two years now! (Mind you, I personally agree that the documentation is correct and the implementation is buggy, so I'd much rather see the implementation fixed. But if the designers of Kotlin don't agree, then at the very least the documentation should reflect what the functions actually do!)

tomyuval avatar Nov 05 '20 16:11 tomyuval

Can we please get this merged? This just fixes the docs to match the implementation, so it's not a breaking change.

While I'd personally prefer to actually change the implementation, that's certainly not going to happen any time soon. In any case, docs and implementation should stay aligned.

sschuberth avatar Feb 16 '21 21:02 sschuberth

As this has been fixed as part of another PR, I'm going to close this PR. Thanks for your input!

sarahhaggarty avatar Jul 31 '23 12:07 sarahhaggarty