Skip to content

Conversation

KacperFKorban
Copy link
Member

closes #22620

@KacperFKorban
Copy link
Member Author

It looks like this change breaks a pattern that used to work before e.g.:

sealed abstract class Tree[+A](
  final val key: A
)
final class RedTree[+A](key: A) extends Tree[A](key)
object RedTree {
  def unapply[A](t: RedTree[A]) = Some((t.key))
}

Since we prefer choosing private members when there are multiple denotations, then this example breaks, since:

  1. Parameter key from RedTree is private local at first
  2. We try accessing it from the companion object and make it non local as a consequence
  3. It becomes private, so it clashes with the inherited final val key

The decision was to also allow for class parameters to be inferred as private local, but looks like it might be a trade-off.

Note: I tried changing the compiler, so that the non-private denotation is preferred, but that broke too many things.

@mbovel
Copy link
Member

mbovel commented Sep 10, 2025

Closed in favor of #23871.

@mbovel mbovel closed this Sep 10, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

private[this] inference does not work for constructor parameters
2 participants