Skip to content

Commit 6422ef8

Browse files
committed
Rename Eq -> Eql
Eq is already used with a slightly different meaning as a unary typeclass, e.g. cats.Eq.
1 parent dcd3f55 commit 6422ef8

21 files changed

+95
-104
lines changed

compiler/src/dotty/tools/dotc/core/Definitions.scala

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -730,11 +730,11 @@ class Definitions {
730730
lazy val TastyReflectionModule: TermSymbol = ctx.requiredModule("scala.tasty.Reflection")
731731
lazy val TastyReflection_macroContext: TermSymbol = TastyReflectionModule.requiredMethod("macroContext")
732732

733-
lazy val EqType: TypeRef = ctx.requiredClassRef("scala.Eq")
734-
def EqClass(implicit ctx: Context): ClassSymbol = EqType.symbol.asClass
735-
def EqModule(implicit ctx: Context): Symbol = EqClass.companionModule
733+
lazy val EqlType: TypeRef = ctx.requiredClassRef("scala.Eql")
734+
def EqlClass(implicit ctx: Context): ClassSymbol = EqlType.symbol.asClass
735+
def EqlModule(implicit ctx: Context): Symbol = EqlClass.companionModule
736736

737-
def Eq_eqAny(implicit ctx: Context): TermSymbol = EqModule.requiredMethod(nme.eqAny)
737+
def Eql_eqlAny(implicit ctx: Context): TermSymbol = EqlModule.requiredMethod(nme.eqlAny)
738738

739739
lazy val NotType: TypeRef = ctx.requiredClassRef("scala.implicits.Not")
740740
def NotClass(implicit ctx: Context): ClassSymbol = NotType.symbol.asClass

compiler/src/dotty/tools/dotc/core/Denotations.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ import collection.mutable.ListBuffer
6767
*/
6868
object Denotations {
6969

70-
implicit def eqDenotation: Eq[Denotation, Denotation] = Eq.derived
70+
implicit def eqDenotation: Eql[Denotation, Denotation] = Eql.derived
7171

7272
/** A PreDenotation represents a group of single denotations or a single multi-denotation
7373
* It is used as an optimization to avoid forming MultiDenotations too eagerly.

compiler/src/dotty/tools/dotc/core/Names.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ object Names {
2525
def toTermName: TermName
2626
}
2727

28-
implicit def eqName: Eq[Name, Name] = Eq.derived
28+
implicit def eqName: Eql[Name, Name] = Eql.derived
2929

3030
/** A common superclass of Name and Symbol. After bootstrap, this should be
3131
* just the type alias Name | Symbol

compiler/src/dotty/tools/dotc/core/StdNames.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -417,7 +417,7 @@ object StdNames {
417417
val equals_ : N = "equals"
418418
val error: N = "error"
419419
val eval: N = "eval"
420-
val eqAny: N = "eqAny"
420+
val eqlAny: N = "eqlAny"
421421
val ex: N = "ex"
422422
val experimental: N = "experimental"
423423
val f: N = "f"

compiler/src/dotty/tools/dotc/core/Symbols.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -406,7 +406,7 @@ trait Symbols { this: Context =>
406406

407407
object Symbols {
408408

409-
implicit def eqSymbol: Eq[Symbol, Symbol] = Eq.derived
409+
implicit def eqSymbol: Eql[Symbol, Symbol] = Eql.derived
410410

411411
/** Tree attachment containing the identifiers in a tree as a sorted array */
412412
val Ids: Property.Key[Array[String]] = new Property.Key

compiler/src/dotty/tools/dotc/core/Types.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ object Types {
4040

4141
@sharable private[this] var nextId = 0
4242

43-
implicit def eqType: Eq[Type, Type] = Eq.derived
43+
implicit def eqType: Eql[Type, Type] = Eql.derived
4444

4545
/** Main class representing types.
4646
*

compiler/src/dotty/tools/dotc/typer/Implicits.scala

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -698,18 +698,18 @@ trait Implicits { self: Typer =>
698698
if (ctx.inInlineMethod || enclosingInlineds.nonEmpty) ref(defn.TastyReflection_macroContext)
699699
else EmptyTree
700700

701-
/** If `formal` is of the form Eq[T, U], try to synthesize an
702-
* `Eq.eqAny[T, U]` as solution.
701+
/** If `formal` is of the form Eql[T, U], try to synthesize an
702+
* `Eql.eqlAny[T, U]` as solution.
703703
*/
704704
def synthesizedEq(formal: Type)(implicit ctx: Context): Tree = {
705705

706706
/** Is there an `Eql[T, T]` instance, assuming -strictEquality? */
707707
def hasEq(tp: Type)(implicit ctx: Context): Boolean = {
708-
val inst = inferImplicitArg(defn.EqType.appliedTo(tp, tp), span)
708+
val inst = inferImplicitArg(defn.EqlType.appliedTo(tp, tp), span)
709709
!inst.isEmpty && !inst.tpe.isError
710710
}
711711

712-
/** Can we assume the eqAny instance for `tp1`, `tp2`?
712+
/** Can we assume the eqlAny instance for `tp1`, `tp2`?
713713
* This is the case if assumedCanEqual(tp1, tp2), or
714714
* one of `tp1`, `tp2` has a reflexive `Eql` instance.
715715
*/
@@ -755,7 +755,7 @@ trait Implicits { self: Typer =>
755755
||
756756
!strictEquality &&
757757
ctx.test(implicit ctx => validEqAnyArgs(arg1, arg2)))
758-
ref(defn.Eq_eqAny).appliedToTypes(args).withSpan(span)
758+
ref(defn.Eql_eqlAny).appliedToTypes(args).withSpan(span)
759759
else EmptyTree
760760
case _ =>
761761
EmptyTree
@@ -816,7 +816,7 @@ trait Implicits { self: Typer =>
816816
trySpecialCase(defn.QuotedTypeClass, synthesizedTypeTag,
817817
trySpecialCase(defn.GenericClass, synthesizedGeneric,
818818
trySpecialCase(defn.TastyReflectionClass, synthesizedTastyContext,
819-
trySpecialCase(defn.EqClass, synthesizedEq,
819+
trySpecialCase(defn.EqlClass, synthesizedEq,
820820
trySpecialCase(defn.ValueOfClass, synthesizedValueOf, failed))))))
821821
}
822822
}
@@ -962,8 +962,8 @@ trait Implicits { self: Typer =>
962962
/** Check that equality tests between types `ltp` and `rtp` make sense */
963963
def checkCanEqual(ltp: Type, rtp: Type, span: Span)(implicit ctx: Context): Unit =
964964
if (!ctx.isAfterTyper && !assumedCanEqual(ltp, rtp)) {
965-
val res = implicitArgTree(defn.EqType.appliedTo(ltp, rtp), span)
966-
implicits.println(i"Eq witness found for $ltp / $rtp: $res: ${res.tpe}")
965+
val res = implicitArgTree(defn.EqlType.appliedTo(ltp, rtp), span)
966+
implicits.println(i"Eql witness found for $ltp / $rtp: $res: ${res.tpe}")
967967
}
968968

969969
/** Find an implicit parameter or conversion.
@@ -1031,7 +1031,7 @@ trait Implicits { self: Typer =>
10311031
if (argument.isEmpty) f(resultType) else ViewProto(f(argument.tpe.widen), f(resultType))
10321032
// Not clear whether we need to drop the `.widen` here. All tests pass with it in place, though.
10331033

1034-
private def isCoherent = pt.isRef(defn.EqClass)
1034+
private def isCoherent = pt.isRef(defn.EqlClass)
10351035

10361036
private val cmpContext = nestedContext()
10371037
private val cmpCandidates = (c1: Candidate, c2: Candidate) => compare(c1.ref, c2.ref, c1.level, c2.level)(cmpContext)

compiler/src/dotty/tools/dotc/util/SourceFile.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ class SourceFile(val file: AbstractFile, computeContent: => Array[Char]) extends
190190
}
191191
}
192192
object SourceFile {
193-
implicit def eqSource: Eq[SourceFile, SourceFile] = Eq.derived
193+
implicit def eqSource: Eql[SourceFile, SourceFile] = Eql.derived
194194

195195
implicit def fromContext(implicit ctx: Context): SourceFile = ctx.source
196196

compiler/test-resources/repl/i4184

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ scala> object foo { class Foo }
22
// defined object foo
33
scala> object bar { class Foo }
44
// defined object bar
5-
scala> implicit def eqFoo: Eq[foo.Foo, foo.Foo] = Eq.derived
6-
def eqFoo: Eq[foo.Foo, foo.Foo]
5+
scala> implicit def eqFoo: Eql[foo.Foo, foo.Foo] = Eql.derived
6+
def eqFoo: Eql[foo.Foo, foo.Foo]
77
scala> object Bar { new foo.Foo == new bar.Foo }
88
1 | object Bar { new foo.Foo == new bar.Foo }
99
| ^^^^^^^^^^^^^^^^^^^^^^^^^^

docs/docs/reference/enums/desugarEnums.md

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -134,15 +134,6 @@ map into case classes or vals.
134134
where `n` is the ordinal number of the case in the companion object,
135135
starting from 0.
136136

137-
### Equality
138-
139-
An `enum` type contains a `scala.Eq` instance that restricts values of the `enum` type to
140-
be compared only to other values of the same enum type. Furtermore, generic
141-
`enum` types are comparable only if their type arguments are. For instance the
142-
`Option` enum type will get the following definition in its companion object:
143-
144-
implicit def eqOption[T, U](implicit ev1: Eq[T, U]): Eq[Option[T], Option[U]] = Eq
145-
146137
### Translation of Enumerations
147138

148139
Non-generic enums `E` that define one or more singleton cases

library/src/scala/Eq.scala renamed to library/src/scala/Eql.scala

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,33 +5,33 @@ import scala.collection.{GenSeq, Set}
55

66
/** A marker trait indicating that values of type `L` can be compared to values of type `R`. */
77
@implicitNotFound("Values of types ${L} and ${R} cannot be compared with == or !=")
8-
sealed trait Eq[-L, -R]
8+
sealed trait Eql[-L, -R]
99

1010
/** Companion object containing a few universally known `Eql` instances.
1111
* Eql instances involving primitive types or the Null type are handled directly in
1212
* the compiler (see Implicits.synthesizedEq), so they are not included here.
1313
*/
14-
object Eq {
14+
object Eql {
1515
/** A non-implied universal `Eql` instance. */
16-
object derived extends Eq[Any, Any]
16+
object derived extends Eql[Any, Any]
1717

1818
/** A fall-back instance to compare values of any types.
1919
* Even though this method is not declared implied, the compiler will
2020
* compute implied instances as solutions to `Eql[T, U]` queries if
2121
* the rules of multiversal equality require it.
2222
*/
23-
def eqAny[L, R]: Eq[L, R] = derived
23+
def eqlAny[L, R]: Eql[L, R] = derived
2424

25-
// Instances of `Eq` for common Java types
26-
implicit def eqNumber : Eq[Number, Number] = derived
27-
implicit def eqString : Eq[String, String] = derived
25+
// Instances of `Eql` for common Java types
26+
implicit def eqlNumber : Eql[Number, Number] = derived
27+
implicit def eqlString : Eql[String, String] = derived
2828

2929
// The next three definitions can go into the companion objects of classes
3030
// Seq, Set, and Proxy. For now they are here in order not to have to touch the
3131
// source code of these classes
32-
implicit def eqSeq[T, U](implicit eq: Eq[T, U]): Eq[GenSeq[T], GenSeq[U]] = derived
33-
implicit def eqSet[T, U](implicit eq: Eq[T, U]): Eq[Set[T], Set[U]] = derived
32+
implicit def eqlSeq[T, U](implicit eq: Eql[T, U]): Eql[GenSeq[T], GenSeq[U]] = derived
33+
implicit def eqlSet[T, U](implicit eq: Eql[T, U]): Eql[Set[T], Set[U]] = derived
3434

3535
// true asymmetry, modeling the (somewhat problematic) nature of equals on Proxies
36-
implicit def eqProxy : Eq[Proxy, AnyRef] = derived
36+
implicit def eqlProxy : Eql[Proxy, AnyRef] = derived
3737
}

tests/neg/EqualityStrawman1.scala

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,22 @@ import annotation.implicitNotFound
33

44
object EqualityStrawman1 {
55

6-
trait Eq[-T]
6+
trait Eql[-T]
77

88
@implicitNotFound("cannot compare value of type ${T} with a value outside its equality class")
99
trait Impossible[T]
1010

11-
object Eq {
12-
object derived extends Eq[Any]
11+
object Eql {
12+
object derived extends Eql[Any]
1313
}
14-
14+
1515
trait Base {
1616
def === (other: Any): Boolean = this.equals(other)
1717
def === [T <: CondEquals](other: T)(implicit ce: Impossible[T]): Boolean = ???
1818
}
1919

2020
trait CondEquals extends Base {
21-
def === [T >: this.type <: CondEquals](other: T)(implicit ce: Eq[T]): Boolean = this.equals(other)
21+
def === [T >: this.type <: CondEquals](other: T)(implicit ce: Eql[T]): Boolean = this.equals(other)
2222
def === [T](other: T)(implicit ce: Impossible[T]): Boolean = ???
2323
}
2424

@@ -34,11 +34,11 @@ object EqualityStrawman1 {
3434
case class Some[+T](x: T) extends Option[T]
3535
case object None extends Option[Nothing]
3636

37-
implicit def eqStr: Eq[Str] = Eq.derived
38-
//implicit def eqNum: Eq[Num] = Eq.derived
39-
implicit def eqOption[T: Eq]: Eq[Option[T]] = Eq.derived
37+
implicit def eqStr: Eql[Str] = Eql.derived
38+
//implicit def eqNum: Eql[Num] = Eql.derived
39+
implicit def eqOption[T: Eql]: Eql[Option[T]] = Eql.derived
4040

41-
implicit def eqEq[T <: Equals[T]]: Eq[T] = Eq.derived
41+
implicit def eqEq[T <: Equals[T]]: Eql[T] = Eql.derived
4242

4343
def main(args: Array[String]): Unit = {
4444
val x = Str("abc")
@@ -59,7 +59,7 @@ object EqualityStrawman1 {
5959
None === z
6060

6161

62-
def ddistinct[T <: Base: Eq](xs: List[T]): List[T] = xs match {
62+
def ddistinct[T <: Base: Eql](xs: List[T]): List[T] = xs match {
6363
case Nil => Nil
6464
case x :: xs => x :: xs.filterNot(x === _)
6565
}

tests/neg/derive-eq.scala

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
11

2-
case class One() derives Eq
3-
case class Two() derives Eq
2+
case class One() derives Eql
3+
case class Two() derives Eql
44

5-
implied for Eq[One, Two] = Eq.derived
5+
implied for Eql[One, Two] = Eql.derived
66

7-
enum Lst[T] derives Eq {
7+
enum Lst[T] derives Eql {
88
case Cons(x: T, xs: Lst[T])
99
case Nil()
1010
}
1111

12-
case class Triple[S, T, U] derives Eq
12+
case class Triple[S, T, U] derives Eql
1313

1414

1515
object Test extends App {
16-
implicitly[Eq[Lst[Lst[One]], Lst[Lst[Two]]]]
17-
implicitly[Eq[Triple[One, One, One],
16+
implicitly[Eql[Lst[Lst[One]], Lst[Lst[Two]]]]
17+
implicitly[Eql[Triple[One, One, One],
1818
Triple[Two, Two, Two]]]
1919

2020
val x: Triple[List[One], One, Two] = ???

tests/neg/enums.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ enum E4 {
2424
case class C4() extends E4 // error: cannot extend enum
2525
case object O4 extends E4 // error: cannot extend enum
2626

27-
enum Option[+T] derives Eq {
27+
enum Option[+T] derives Eql {
2828
case Some(x: T)
2929
case None
3030
}

tests/neg/equality.scala

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,20 +10,20 @@ object equality {
1010
case class Some[+T](x: T) extends Option[T]
1111
case object None extends Option[Nothing]
1212

13-
implicit def eqStr: Eq[Str, Str] = Eq.derived
14-
implicit def eqNum: Eq[Num, Num] = Eq.derived
15-
implicit def eqOption[T, U](implicit e: Eq[T, U]): Eq[Option[T], Option[U]] = Eq.derived
13+
implicit def eqStr: Eql[Str, Str] = Eql.derived
14+
implicit def eqNum: Eql[Num, Num] = Eql.derived
15+
implicit def eqOption[T, U](implicit e: Eql[T, U]): Eql[Option[T], Option[U]] = Eql.derived
1616

1717
case class PString(a: String) extends Proxy {
1818
def self = a
1919
}
2020

2121
/*
22-
implicit def eqString: Eq[String, String] = Eq.derived
23-
implicit def eqInt: Eq[Int, Int] = Eq.derived
24-
implicit def eqNumber: Eq[Number, Number] = Eq.derived
25-
implicit def eqIntNumber: Eq[Int, Number] = Eq.derived
26-
implicit def eqNumberInt: Eq[Number, Int] = Eq.derived
22+
implicit def eqString: Eql[String, String] = Eql.derived
23+
implicit def eqInt: Eql[Int, Int] = Eql.derived
24+
implicit def eqNumber: Eql[Number, Number] = Eql.derived
25+
implicit def eqIntNumber: Eql[Int, Number] = Eql.derived
26+
implicit def eqNumberInt: Eql[Number, Int] = Eql.derived
2727
*/
2828
def main(args: Array[String]): Unit = {
2929
Some(Other(3)) == None
@@ -64,7 +64,7 @@ object equality {
6464
1 == null // error
6565

6666

67-
class Fruit derives Eq
67+
class Fruit derives Eql
6868

6969
class Apple extends Fruit
7070
class Pear extends Fruit

tests/neg/i3976.scala

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
object Test {
2-
enum Hoge[F[_]] derives Eq {
2+
enum Hoge[F[_]] derives Eql {
33
case A extends Hoge[List]
44
case B extends Hoge[[X] => String]
55
}
@@ -8,7 +8,7 @@ object Test {
88
A == A
99
A == (B: Hoge[_])
1010

11-
A == B // should be error: cannot be compared, needs proper typeclass drivation of `Eq` to get there.
11+
A == B // should be error: cannot be compared, needs proper typeclass drivation of `Eql` to get there.
1212

1313
class C
1414

@@ -18,7 +18,7 @@ object Test {
1818
}
1919

2020
object Test2 {
21-
enum Hoge[F[G[_]]] derives Eq {
21+
enum Hoge[F[G[_]]] derives Eql {
2222
case A extends Hoge[[F[_]] => F[Int]]
2323
case B extends Hoge[[F[_]] => F[String]]
2424
}
@@ -37,7 +37,7 @@ object Test2 {
3737
}
3838

3939
object Test3 {
40-
enum Hoge[F[G[_]]] derives Eq {
40+
enum Hoge[F[G[_]]] derives Eql {
4141
case A extends Hoge[[X] => List] // error: wrong kind
4242
case B extends Hoge[[X] => [Y] => String] // error: wrong kind
4343
}

tests/neg/i4470b.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
object RepeatedExtendEnum {
22

3-
enum Maybe[T] derives Eq { // error // error
3+
enum Maybe[T] derives Eql { // error // error
44
case Foo extends Maybe[Int]
55
}
66

7-
enum Maybe[T] derives Eq { // error
7+
enum Maybe[T] derives Eql { // error
88
case Foo extends Maybe[Int]
99
}
1010
}

tests/neg/i5546.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@ object O {
88
val m: Meters = 1.0
99
assert(m == 1.0) // OK
1010
}
11-
implicit def eqM: Eq[Meters, Meters] = Eq.derived
11+
implicit def eqM: Eql[Meters, Meters] = Eql.derived
1212

1313
opaque type Feet = Double
1414
object Feet { def apply(d: Double): Feet = d }
15-
implicit def eqF: Eq[Feet, Feet] = Eq.derived
15+
implicit def eqF: Eql[Feet, Feet] = Eql.derived
1616

1717
def main(args: Array[String]): Unit = {
1818
println(Feet(3) == Meters(3)) // error: cannot compare

0 commit comments

Comments
 (0)