Skip to content

Documentation and error messages for synthesized _${n} selectors on case classes #4520

Open
@gsps

Description

@gsps

The new behavior in synthesizing selectors _1, _2, etc. to a case classes' fields caught me by surprise, especially since the error messages may turn out to be quite useless:

trait EdgeLike[T] {
  def _1: T
  def _2: T
}

case class LabeledEdge[T, U](_1: T, label: U, _2: T) extends EdgeLike[T]

leads to

-- [E007] Type Mismatch Error: try/CaseClassSelectors.scala:6:51 ---------------
6 |case class LabeledEdge[T, U](_1: T, label: U, _2: T) extends EdgeLike[T]
  |                                                   ^
  |                                       found:    U(LabeledEdge.this.label)
  |                                       required: T
  |                                       
-- [E119] Duplicate Symbol Error: try/CaseClassSelectors.scala:6:46 ------------
6 |case class LabeledEdge[T, U](_1: T, label: U, _2: T) extends EdgeLike[T]
  |                                              ^
  |value _2 in class LabeledEdge is already defined as def _2: => T at line 6.

Retrospectively, I probably also ran into a very annoying interaction of this and implicits: I was expecting an implicit class with members _1 and _2 to be found, but instead got the new members on the non-wrapped class.

At a minimum, we should document the new synthesis behavior on case classes.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions