bug icon indicating copy to clipboard operation
bug copied to clipboard

`StringOps.concat` and `++` have inconsistent signatures

Open noresttherein opened this issue 1 year ago • 2 comments

Scala 2.13.14

  def concat[B >: Char](suffix: IterableOnce[B]): immutable.IndexedSeq[B] = ...
  def concat(suffix: IterableOnce[Char]): String = ...
  @`inline` def concat(suffix: String): String = ...

  /** Alias for `concat` */
  @`inline` def ++[B >: Char](suffix: Iterable[B]): immutable.IndexedSeq[B] = concat(suffix)

  /** Alias for `concat` */
  @`inline` def ++(suffix: IterableOnce[Char]): String = concat(suffix)

  /** Alias for `concat` */
  def ++(xs: String): String = concat(xs)

Problem

concat accepts [U >: Char] IterableOnce[U], but ++ only Iterable[U]. I'm sorry if it is as intended, by there is no comment as to why, docs explicitly mention it as an alias, which somewhat implies equivalent signatures, and it seems to go against the Scala 3 principles.

BTW, there is also Map.+ without a Map.add, but that's a minor inconsistency, certainly not a bug.

noresttherein avatar Sep 24 '24 18:09 noresttherein

Probably an oversight at https://github.com/scala/scala/commit/79db90986a2f26aeea39e586cabda2926fb69987 where there is explanation or back story.

Probably the signature can't change until they unfreeze the library, but someone could add a line of doc which would have to be reverted later.

I know Martin Odersky is the Scala 3 principal, but I don't know what their principles are.

som-snytt avatar Sep 28 '24 05:09 som-snytt

@scala/collections

SethTisue avatar Oct 10 '24 02:10 SethTisue