Skip to content

Equatability of Nothing with types which are otherwise unequatable #13512

Closed
@jcracknell

Description

@jcracknell

I have been experimenting with strict equality in 3.0.2 and immediately ran into the issue where you cannot pattern match against Nil/None. I see the efforts to address this in 3.1.0 in 3e963c0 and 32a99fd, however I am not sure that this is the correct approach, as the following is still illegal:

class NotEquatable

List(new NotEquatable) match
  case Nil => ???

This can be addressed by instead adding the following givens permitting equating Nothing with any type regardless of the equatability of that type, on the basis that you could never actually invoke the equality test:

given canEqualNothingL: CanEqual[Nothing, Any] = CanEqual.derived
given canEqualNothingR: CanEqual[Any, Nothing] = CanEqual.derived

With this addition it appears you can remove the supplementary CanEqual.canEqual{Seq,Option} previously added to address matching Nil/None in the above-mentioned commits.

I will note that you do get this awkward behavior already present in 2.x:

??? == 42 // runtime error
42 == ??? // compile error, ambiguous overload

this could perhaps be addressed by adding an overload to Any, however I am uncertain of the viability of such an approach:

def equals(nothing: Nothing): Boolean = ???

Metadata

Metadata

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions