Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handles Nothing when synthesizing CanEqual #13828

Merged
merged 1 commit into from
Oct 27, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions compiler/src/dotty/tools/dotc/typer/Synthesizer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,8 @@ class Synthesizer(typer: Typer)(using @constructorOnly c: Context):
def canComparePredefinedClasses(cls1: ClassSymbol, cls2: ClassSymbol): Boolean =

def cmpWithBoxed(cls1: ClassSymbol, cls2: ClassSymbol) =
cls2 == defn.boxedType(cls1.typeRef).symbol
cls2 == defn.NothingClass
|| cls2 == defn.boxedType(cls1.typeRef).symbol
|| cls1.isNumericValueClass && cls2.derivesFrom(defn.BoxedNumberClass)

if cls1.isPrimitiveValueClass then
Expand All @@ -129,7 +130,7 @@ class Synthesizer(typer: Typer)(using @constructorOnly c: Context):
else if cls2 == defn.NullClass then
cls1.derivesFrom(defn.ObjectClass)
else
false
cls1 == defn.NothingClass || cls2 == defn.NothingClass
end canComparePredefinedClasses

/** Some simulated `CanEqual` instances for predefined types. It's more efficient
Expand Down
7 changes: 7 additions & 0 deletions tests/pos/i13512.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import scala.language.strictEquality

class NotEquatable

def f = List(new NotEquatable) match
case Nil => ???
case _ =>
46 changes: 46 additions & 0 deletions tests/pos/i13739.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import scala.language.strictEquality

class Foo(i: Int) extends AnyVal

val _ = summon[CanEqual[Nothing, Nothing]]

val _ = summon[CanEqual[Int, Nothing]]
val _ = summon[CanEqual[Nothing, Int]]
val _ = summon[CanEqual[3, Nothing]]
val _ = summon[CanEqual[Nothing, 3]]

val _ = summon[CanEqual[Byte, Nothing]]
val _ = summon[CanEqual[Nothing, Byte]]
val _ = summon[CanEqual[Short, Nothing]]
val _ = summon[CanEqual[Nothing, Short]]
val _ = summon[CanEqual[Float, Nothing]]
val _ = summon[CanEqual[Nothing, Float]]

val _ = summon[CanEqual[Double, Nothing]]
val _ = summon[CanEqual[Nothing, Double]]
val _ = summon[CanEqual[3.0, Nothing]]
val _ = summon[CanEqual[Nothing, 3.0]]

val _ = summon[CanEqual[String, Nothing]]
val _ = summon[CanEqual[Nothing, String]]
val _ = summon[CanEqual["foo", Nothing]]
val _ = summon[CanEqual[Nothing, "foo"]]

val _ = summon[CanEqual[Char, Nothing]]
val _ = summon[CanEqual[Nothing, Char]]
val _ = summon[CanEqual['f', Nothing]]
val _ = summon[CanEqual[Nothing, 'f']]

val _ = summon[CanEqual[Boolean, Nothing]]
val _ = summon[CanEqual[Nothing, Boolean]]
val _ = summon[CanEqual[true, Nothing]]
val _ = summon[CanEqual[Nothing, true]]

val _ = summon[CanEqual[Foo, Nothing]]
val _ = summon[CanEqual[Nothing, Foo]]

val _ = summon[CanEqual[Option[Int], None.type]]
val _ = summon[CanEqual[Option[Int], Option[Nothing]]]

val _ = summon[CanEqual[Any & Nothing, Foo]]
val _ = summon[CanEqual[Nothing & Any, Foo]]