@@ -56,26 +56,31 @@ each other, but not comparable to anything else:
56
56
(As usual, the names of the implicit definitions don't matter, we have
57
57
chosen ` eqA ` , ..., ` eqBA ` only for illustration).
58
58
59
- The ` dotty.DottyPredef ` object defines a number of ` Eq `
60
- implicits. ` dotty.DottyPredef ` is a temporary ` Predef ` -like object.
61
- The contents of this object are by default imported into every
62
- program. Once dotty becomes standard Scala, ` DottyPredef ` will go away
63
- and its contents will be merged with ` scala.Predef ` .
59
+ The ` scala.Eq ` object defines a number of ` Eq ` implicits that make
60
+ values of types ` String ` , ` Boolean ` and ` Unit ` only comparable to
61
+ values of the same type. They also make numbers only comparable to
62
+ other numbers, sequences only comparable to other
63
+ sequences and sets only comparable to other sets .
64
64
65
- The ` Eq ` instances defined by ` DottyPredef ` make values of types
66
- ` String ` , ` Boolean ` and ` Unit ` only comparable to values of the same
67
- type. They also make numbers only comparable to other numbers, and
68
- sequences only comparable to other sequences. There's also a
69
- "fallback" instance ` eqAny ` that allows comparisons over types that do
70
- not themeselves have an ` Eq ` instance. ` eqAny ` is defined as follows:
65
+ There's also a "fallback" instance named ` eqAny ` that allows comparisons
66
+ over all types that do not themeselves have an ` Eq ` instance. ` eqAny ` is
67
+ defined as follows:
71
68
72
- implicit def eqAny[L, R]: Eq[L, R] = Eq
69
+ def eqAny[L, R]: Eq[L, R] = Eq
70
+
71
+ Even though ` eqAny ` is not declared implicit, the compiler will still
72
+ construct an ` eqAny ` instance as answer to an implicit search for the
73
+ type ` Eq[L, R] ` , provided that neither ` L ` nor ` R ` have ` Eq ` instances
74
+ defined on them.
73
75
74
76
The primary motivation for having ` eqAny ` is backwards compatibility,
75
- if this is of no concern one can disable ` eqAny ` by unimporting it
76
- from ` DottyPredef ` like this
77
+ if this is of no concern one can disable ` eqAny ` by enabling the language
78
+ feature ` strictEquality ` . As for all language features this can be either
79
+ done with an import
80
+
81
+ import scala.language.strictEquality
77
82
78
- import dotty.DottyPredef.{eqAny => _, _}
83
+ or with a command line option ` -language:strictEquality ` .
79
84
80
85
All ` enum ` types also come with ` Eq ` instances that make values of the
81
86
` enum ` type comparable only to other values of that ` enum ` type.
@@ -87,11 +92,11 @@ The precise rules for equality checking are as follows.
87
92
of the other, or an implicit value of type ` scala.Eq[T, U] ` is found.
88
93
89
94
2 . The usual rules for implicit search apply also to ` Eq ` instances,
90
- with one modification: The value ` eqAny ` in ` dotty.DottyPredef ` is
91
- eligible only if neither ` T ` nor ` U ` have a reflexive ` Eq `
95
+ with one modification: An instance of ` scala.Eq.eqAny[T, U] ` is
96
+ constructed if neither ` T ` nor ` U ` have a reflexive ` Eq `
92
97
instance themselves. Here, a type ` T ` has a reflexive ` Eq `
93
- instance if the implicit search for ` Eq[T, T] ` where ` eqAny ` is
94
- not eligible is successful .
98
+ instance if the implicit search for ` Eq[T, T] ` succeeds
99
+ and constructs an instance different from ` eqAny ` .
95
100
96
101
More on multiversal equality is found in a [ blog post]
97
102
and a [ Github issue] .
0 commit comments