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.

Document given CanEqual on companion objects

See original GitHub issue

Compiler version

scala 3.0

Minimized example

import scala.language.strictEquality

case class Suit(value: String)

object Suit:
  given CanEqual[Suit, Suit] = CanEqual.derived

@main def main =
  println(Suit("X") == Suit("X"))

Output

true

Expectation

According to https://github.com/lampepfl/dotty/blob/a9a7e7042408dd0de6cebdddc5fc23a6e33d26be/docs/docs/reference/contextual/multiversal-equality.md#precise-rules-for-equality-checking objects can be compared using == under strictEquality if there is a given of type CanEqual[T, U].

In the example above it’s not clear (to me) and I can’t find documentation as to why the given CanEqual in the companion object is available in this case. AFAICT, it is in general not available as given at the main scope without an import.

Thank you

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:6 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
som-snyttcommented, Jun 6, 2021

@amitport The amended doc is at https://dotty.epfl.ch/docs/reference/changed-features/implicit-resolution.html

The relevant section is Nr 3, which I had previously skipped because of tldr; The terminology is revised but the gist is similar.

There is a TODO on the page to refine it.

I agree that if I’ve read something in the reference docs, but I need to find it again because I haven’t had enough opportunity to use Scala 3, it can be hard to find what I need. Sometimes I grep the repo.

I don’t know how this topic is covered in introductory materials.

0reactions
amitportcommented, Jun 6, 2021

Thanks, I saw that one, but it’s not really “reader-friendly”, and missing some details.

Hopefully, at some point, scala3 language guides would contain all the language semantics without referring to scala2 language specification (the reference is also missing in this case) + migration guide.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Multiversal Equality
CanEqual object defines a number of CanEqual given instances that together define a rule book for what standard types can be compared (more...
Read more >
How do I create an explicit companion object for a case class ...
When defining an explicit companion object for a case class (as of Scala ... Object> productIterator(); public boolean canEqual(java.lang.
Read more >
ScalaMock 4.2.0 - org.scalamock.matchers.MatchEpsilon - javadoc.io
Companion object MatchEpsilon ... Matcher that matches all numbers that are close to a given value. Linear Supertypes ... def canEqual(that: Any): Boolean....
Read more >
Scalactic 3.0.9 - org.scalactic
Companion object for trait Equivalence that provides a factory method for producing default Equivalence instances. object Every extends Serializable.
Read more >
Scala: Class and Object | by Knoldus Inc. - Medium
Scala classes are blueprint or template for creating objects. ... Companion object is defined in the same source file in which the class...
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