Skip to content

Commit 36f1f5f

Browse files
committed
Augment strawman with null comparisons.
Null was ignored so far, but it requires more overloads to work correctly.
1 parent 05bfe78 commit 36f1f5f

File tree

1 file changed

+11
-9
lines changed

1 file changed

+11
-9
lines changed

tests/neg/EqualityStrawman1.scala

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,31 +12,31 @@ object EqualityStrawman1 {
1212

1313
trait Base {
1414
def === (other: Any): Boolean = this.equals(other)
15-
def === [T <: CondEquals](other: T)(implicit ce: Impossible[T]): Boolean = ???
15+
def === (other: Null): Boolean = this.equals(other)
16+
def === [T <: EqClass](other: T)(implicit ce: Impossible[T]): Boolean = ???
1617
}
1718

18-
trait CondEquals extends Base {
19-
def === [T >: this.type <: CondEquals](other: T)(implicit ce: Eq[T]): Boolean = this.equals(other)
19+
trait EqClass[-U] extends Base {
20+
def === [T >: this.type <: EqClass](other: T)(implicit ce: Eq[T]): Boolean = this.equals(other)
2021
def === [T](other: T)(implicit ce: Impossible[T]): Boolean = ???
22+
def === (other: Null): Boolean = this.equals(other)
2123
}
2224

23-
trait Equals[-T] extends CondEquals
25+
case class Str(str: String) extends EqClass[_]
2426

25-
case class Str(str: String) extends CondEquals
26-
27-
case class Num(x: Int) extends Equals[Num]
27+
case class Num(x: Int) extends EqClass[Num]
2828

2929
case class Other(x: Int) extends Base
3030

31-
trait Option[+T] extends CondEquals
31+
trait Option[+T] extends EqClass[_]
3232
case class Some[+T](x: T) extends Option[T]
3333
case object None extends Option[Nothing]
3434

3535
implicit def eqStr: Eq[Str] = Eq
3636
//implicit def eqNum: Eq[Num] = Eq
3737
implicit def eqOption[T: Eq]: Eq[Option[T]] = Eq
3838

39-
implicit def eqEq[T <: Equals[T]]: Eq[T] = Eq
39+
implicit def eqEq[T <: EqClass[T]]: Eq[T] = Eq
4040

4141
def main(args: Array[String]): Unit = {
4242
val x = Str("abc")
@@ -56,6 +56,8 @@ object EqualityStrawman1 {
5656
Some(x) === z
5757
None === z
5858

59+
Other(3) === null
60+
Str("x") === null
5961

6062
def ddistinct[T <: Base: Eq](xs: List[T]): List[T] = xs match {
6163
case Nil => Nil

0 commit comments

Comments
 (0)