Skip to content

Inconsistent export of case classes' synthetic methods #13228

Closed
@tabdulradi

Description

@tabdulradi

Compiler version

3.0.1

Minimized code

case class User(name: String)

case class RegisteredUser(id: String, data: User) {
  export data.*
}

@main def app() = 
  println(RegisteredUser("Id", User("Name"))) // RegisteredUser(Name)
  println(RegisteredUser("Id", User("Name")).canEqual(User("Name"))) // True
  // The rest works as expected
  println(RegisteredUser("Id", User("Name")) == User("Name")) // False
  println(RegisteredUser("Id", User("Name")).hashCode == User("Name").hashCode) // False

Output

RegisteredUser(Name)
true
false
false

Expectation

RegisteredUser(Id, User(Name))
false
false
false

According to @bishabosha

So what's happening here is that productArity and productElement are delegated to data field, (those methods are called from toString) but equals, hashCode, toString are not exported. (problematic that canEqual is also exported)

and
@kubukoz

Yeah, strange. toString defers to productPrefix I think, that should probably have been exported as well...

[1] https://twitter.com/bishabosha/status/1421803014722052098
[2] https://twitter.com/kubukoz/status/1421810894967906304

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions