question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Inconsistent `export` of case classes' synthetic methods

See original GitHub issue

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

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:5 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
smartercommented, Aug 1, 2021

I think we do have a problem here because the result is not consistent under separate compilation, if I split the example into a file containing just:

case class User(name: String)

which I then compile, followed by compiling the rest of the example I get:

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

because the PostTyper phase added synthetic definitions for canEqual/productXXX and wildcard exports filters synthetic definitions out: https://github.com/lampepfl/dotty/blob/9e8d5c55153fdbe0d3f78d661cb3b51113403128/compiler/src/dotty/tools/dotc/typer/Namer.scala#L1159

0reactions
oderskycommented, Aug 1, 2021

@smarter Fair point 😃

Read more comments on GitHub >

github_iconTop Results From Across the Web

COMPLIANCE GUIDELINES: HOW TO DEVELOP AN ...
These Guidelines promote good export compliance practices and have been developed to help companies like yours create an effective EMCP that will minimize...
Read more >
Aggregated Damages in a Class Action Suit Found ...
In a case of first impression, a Pennsylvania federal court determined that class action damages based on a trading model that aggregated damages...
Read more >
Find and fix inconsistent B-tree indexes - Google Cloud
Inconsistencies in database indexes can occur for a variety of reasons including software defects, hardware issues, or underlying changes in behavior such ...
Read more >
Case Classes | Tour of Scala
Case classes are like regular classes with a few key differences which we will go over. Case classes are good for modeling immutable...
Read more >
REASONING WITH INCONSISTENT ONTOLOGIES ...
Given a query posed w.r.t. an inconsistent ontology, a dialectical analysis will be performed on a DeLP program obtained from such an ontology, ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found