Open charpov opened 1 month ago
@scala/collections
I just noticed 3-indent. 🤯
I just noticed 3-indent. 🤯
When Scala 3 was new, there was a discussion somewhere that 3-indent would be the norm (maybe it wasn't serious). I adopted it (including all the code examples in a book) and I'm very happy with it. Four is too much for me, and 2 (which I use in Java) not enough when omitting braces. BTW, it looks like ADA style guides recommend using a 3-indent... 😉
Here's a self-contained example that shows the incorrect behavior:
(I use Scala 3 syntax but this is a Scala 2 library issue). The output is:
Notice how
mutable.Map
andmutable.LongMap
produce different outputs whengetOrElseUpdate
is used. When not used, it is replaced with an implementation similar to what's inMapOps
(I usecontains
instead ofget
because I ignore values, but the behavior is the same withget
).I believe this is a bug because
LongMap#getOrElseUpdate
should behave as the defaultMapOps
implementation and becauseLongMap[Unit]
should behave likeMap[Long,Unit]
(in a single-threaded context).One could argue that
getOrElseUpdate
makes no such guarantees when the by-value code modifies the map, but:LongMap#getOrElseUpdate
source that says:which suggests that an effort was made to handle this situation.
I'm using Scala 3.5.2 (which seems to be using the 2.13.14 collections) in my experiments.