Document given CanEqual on companion objects
See original GitHub issueCompiler 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:
- Created 2 years ago
- Comments:6 (1 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@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.
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.