Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

StringOps.concat and ++ have inconsistent signatures #13036

Open
noresttherein opened this issue Sep 24, 2024 · 2 comments
Open

StringOps.concat and ++ have inconsistent signatures #13036

noresttherein opened this issue Sep 24, 2024 · 2 comments

Comments

@noresttherein
Copy link

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
Copy link

Probably an oversight at scala/scala@79db909 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
Copy link
Member

@scala/collections

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants