Enumeration should derive `CanEqual`
See original GitHub issueWhen using an enumeration, we expect pattern matching on the objects to work by default even under strictEquality
.
Compiler version
v3.1.0-RC1
Minimized code
import scala.language.strictEquality
enum FooBar:
case Foo, Bar
def check(fb : FooBar): Unit =
fb match
case FooBar.Foo =>
case FooBar.Bar =>
Output
Values of types FooBar and FooBar cannot be compared with == or !=
Values of types FooBar and FooBar cannot be compared with == or !=
Expectation
No error.
Issue Analytics
- State:
- Created 2 years ago
- Reactions:2
- Comments:10 (5 by maintainers)
Top Results From Across the Web
Enumeration does not derive `CanEqual` for `strictEquality ...
I started experimenting with strictEquality just recently. Once it's on it pretty much requires you to have it specified on every case class...
Read more >[Solved]-Deriving `CanEqual` succeeds on function when it shouldn ...
Simply speaking, with derives CanEqual here you just give the compiler know that it's legal to use == or != with instances of...
Read more >Comparing Java enum members: == or equals()?
Both are technically correct. If you look at the source code for .equals() , it simply defers to == . I use ==...
Read more >Object Equality - Artima
In fact, it's well known in Java that hashCode and equals should always ... object can equal this one, as determined by the...
Read more >JavaConverters - Scala 3 - EPFL
Enumeration (via asJavaEnumeration) scala.collection.mutable. ... Alternatively, the conversion methods have descriptive names and can be invoked explicitly ...
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
IMO, if you define an
enum
you want to do basic patten matching. If not, then you don’t want anenum
.Somewhat related enums whose cases are singletons should also derive Ordering with this implementation:
Alternatively add the above code to the
SingletonEnumCompanion
in the https://github.com/lampepfl/dotty/pull/14136 PR