# Pre-SIP: relaxed \`strictEquality\` for \`==\` and \`!=\`

**URL:** <https://contributors.scala-lang.org/t/pre-sip-relaxed-strictequality-for-and/7356>\
**Category:** Scala Improvement Process\
**Created:** [January 28, 2026, 6:40am UTC](https://contributors.scala-lang.org/t/pre-sip-relaxed-strictequality-for-and/7356 "2026-01-28T06:40:38Z")\
**Posts on this page:** 1\
**Showing post:** 8

<div class="post-metadata">

**Author:** ![dontgitit](https://contributors.scala-lang.org/user_avatar/contributors.scala-lang.org/dontgitit/32/3368_2.png) [@dontgitit](https://contributors.scala-lang.org/u/dontgitit)\
**Post date:** [January 31, 2026, 9:54am UTC](https://contributors.scala-lang.org/t/pre-sip-relaxed-strictequality-for-and/7356/8 "2026-01-31T09:54:45Z")

</div>

> [@som-snytt](#):
>
> I would have said that `eq` expresses exactly what is intended for a singleton.

That’s fair!

However, `strictEquality` doesn’t apply to `eq`, so again, it would defeat the whole purpose here.

> [@som-snytt](#):
>
> An object might implement an arbitrary `equals`. I meant to add that if you know it doesn’t override `equals`, then of course `==` is OK.

That is objectively true, but

1. it is relatively uncommon to override `equals`, and
2. I would argue something like `override def equals(other: Object): Boolean = false` is a bug / incorrect, even though it’s valid code; it should at the very least be `this eq other` (and I can’t think of a case where that would be undesired)

> [@som-snytt](#):
>
> I think they intended to reinstate some checks that weren’t ported.
> 
> Scala 2 will say
> 
> ```auto
> scala> 1 eq x
> ^
> warning: comparing values of types Integer and String using `eq` will always yield false
> val res0: Boolean = false
> 
> ```

Is `strictEquality` the vehicle “to reinstate some checks that weren’t ported”, or will it be something else?

Taking a couple steps back, I became interested in this topic after shipping some code that was comparing two unrelated types. When I found the issue, I was shocked (coming from Scala 2, I expected to receive the compiler warning about comparing unrelated types that you showed above!). I can’t remember what exactly led me to `strictEquality` (I think maybe it was trying to get scapegoat or scalafix to surface the error, or some other page somewhere that said the language flag has to be enabled?), but I was disappointed with how unruly `CanEqual` was and how much work I had to put in (on an existing codebase), simply for the compiler to give me a warning on `1 == “a”`.

Maybe the aim of `strictEquality` is not really what I’m after; what I’m after is more or less as you said “to reinstate some checks that weren’t ported”. I’d love for some compiler setting/flag that basically does something as simple as (is it simple?):

> Given an expression `a == b`, if the closest common supertype (least upper bound?) of `a` and `b` is `AnyRef` or anything higher (`Any`), then generate a warning.

Is that the same way it was implemented in Scala 2? Is [this](https://github.com/scala/scala/blob/aeda558645cec0d212fa569e1f356e8534699c32/src/compiler/scala/tools/nsc/typechecker/RefChecks.scala#L1267-L1268) the relevant/related code?

---

_[View the full topic](https://contributors.scala-lang.org/t/pre-sip-relaxed-strictequality-for-and/7356)._
