scala / bug

Scala 2 bug reports only. Please, no questions — proper bug reports only.
https://scala-lang.org
232 stars 21 forks source link

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

Open noresttherein opened 2 months ago

noresttherein commented 2 months ago

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.

som-snytt commented 2 months ago

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.

SethTisue commented 1 month ago

@scala/collections