-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
13 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -107,7 +107,7 @@ Eq instances can be obtained in the following ways: | |
|
||
Verified equality for composed case classes via type class derivation: | ||
```scala | ||
case class Email( address:String) derives Eq | ||
case class Email(address: String) derives Eq | ||
|
||
// Only compiles because class Email derives Eq | ||
case class Person( | ||
|
@@ -123,7 +123,7 @@ person == person | |
|
||
Verified equality for composed case classes with type parameters via type class derivation: | ||
```scala | ||
case class Email( address:String) derives Eq | ||
case class Email(address: String) derives Eq | ||
|
||
// Only compiles because the type parameter A is declared with a context bound [A: Eq] | ||
case class Person[A: Eq]( | ||
|
@@ -134,16 +134,19 @@ case class Person[A: Eq]( | |
// Only compiles because class Email derives Eq | ||
val person = Person("Alice", Email("[email protected]")) | ||
|
||
// Only compiles because class Person derives Eq | ||
person == person | ||
``` | ||
|
||
Verified equality for an existing arbitrary class with a given using the same derivation mechanism: | ||
```scala | ||
// Only compiles because SomeProduct conforms to the equality rules | ||
given Eq[SomeProduct] = Eq.derived | ||
enum Weekday: | ||
case Monday, Tuesday, Wednesday // ... | ||
|
||
// Only compiles with the given instance above | ||
SomeProduct() == SomeProduct() | ||
given Eq[Weekday] = Eq.derived | ||
|
||
// Only compiles because given Eq type class instance for Weekday is in scope | ||
Weekday.Monday == Weekday.Monday | ||
``` | ||
|
||
|
||
|
@@ -229,7 +232,7 @@ import java.time.{LocalDate, LocalDateTime} | |
val now = LocalDateTime.now | ||
val later = LocalDateTime.now | ||
|
||
// Compiles out of the box | ||
// Only compiles because given Eq type class instance for LocalDateTime is in scope | ||
now == later | ||
|
||
val today = LocalDate.now | ||
|
@@ -439,7 +442,7 @@ myDay == myDay | |
To guarantee the build has `-language:strictEquality` enabled, include this in your sources: | ||
|
||
```scala | ||
// Does not need to be called, it fails to compile with strict equality turned off | ||
// Fails to compile if strict equality is disabled | ||
checkStrictEqualityBuild() | ||
``` | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -75,6 +75,7 @@ def verified_equality_for_composed_case_classes_with_type_parameters_via_type_cl | |
// Only compiles because class Email derives Eq | ||
val person = Person("Alice", Email("[email protected]")) | ||
|
||
// Only compiles because class Person derives Eq | ||
person == person | ||
|
||
case class SomeProduct() | ||
|