Skip to content

Synthetic CanEqual for primitives does not handle Nothing as a subtype #13739

@jcracknell

Description

@jcracknell

As CanEqual is contravariant, this should be valid and is likely the root cause for issues around matching Nil/None under strict equality:

scala> implicitly[CanEqual[String, Nothing]]
val res0: CanEqual[String, Nothing] = scala.CanEqual$derived$@7c6b997b

scala> implicitly[CanEqual[Int, Nothing]]                                                                          
-- Error:
1 |implicitly[CanEqual[Int, Nothing]]
  |                                  ^
  |          Values of types Int and Nothing cannot be compared with == or !=

https://github.com/lampepfl/dotty/blob/370280bcfa96d1ea15e8b0b59f272dbbb3a982b9/compiler/src/dotty/tools/dotc/typer/Synthesizer.scala#L102-L114

Metadata

Metadata

Labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions