Skip to content

Pattern matching Option with strictEquality #10850

Closed
@joschua-fink

Description

@joschua-fink

Minimized example

val o: Option[Boolean] = Random.nextInt(3) match {
  case 0 => Some(true)
  case 1 => Some(false)
  case 2 => None
} 

o match {
  case Some(true) =>
  case Some(false) =>
  case None =>
}

Output

[error] 22 |      case None =>
[error]    |           ^^^^
[error]    |Values of types object None and Option[Boolean] cannot be compared with == or !=

Expectation

The example does not compile with -language:strictEquality in Scala 3.0.0-M3, because there is no predefined CanEqual for Option according to the documentation. So it is technically not a bug.

To be honest I have not understood multiversal equality completely, yet. But for me it would make sense for this example to compile without providing a CanEqual as user for a Option type which is part of the Scala standard library. It makes also sense for me that something like if Some(true) == None then ??? fails to compile with -language:strictEquality, which it currently does.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions