Skip to content

StringOps.concat and ++ have inconsistent signatures #13036

Open
@noresttherein

Description

@noresttherein

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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions