Skip to content

[Scala 3 book] Section of comparison seems to have an incorrect example #1905

Open
@Guisanpea

Description

@Guisanpea

Hello. While taking a look to the documentation on multiversal comparison I saw that it first says:

By default, in Scala 3 you can still create an equality comparison like this:

case class Cat(name: String)
case class Dog(name: String)
val d = Dog("Fido")
val c = Cat("Morris")

d == c  // false, but it compiles

But with Scala 3 you can disable such comparisons. By (a) importing scala.language.strictEquality or (b) using the -language:strictEquality compiler flag, this comparison no longer compiles:

import scala.language.strictEquality

val rover = Dog("Rover")
val fido = Dog("Fido")
println(rover == fido)   // compiler error

// compiler error message:
// Values of types Dog and Dog cannot be compared with == or !=

I think that the second example tries to create a Dog and a Cat but ends up doing a comparison on two dogs.

Is this the desired example? Because I find it a bit confusing.

If not I can create a quick PR to fix it

Metadata

Metadata

Assignees

Labels

scala-3scala 3 documentation

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions