Skip to content

Strict equality shouldn't allow comparisons between unrelated type parameters #5810

Closed
@Blaisorblade

Description

@Blaisorblade

Currently, even under strict equality, we can compare values of abstract types/type params:

import scala.language.strictEquality
def equal[S, T](s: S, t: T) = s == t

PR #5624 prevented such errors for abstract types, but left this case open.

This behavior is due to the use of lift in the specification of multiversal equality. The stated motivation is to avoid asInstanceOf in code like this:

 def f[T](x: T) = 
      if (x == null) ... 
      else if (x == "abc") ...
      else ...

However, under strictEquality it seems reasonable to reject x == "abc" and require (x: Any) == "abc".

This issue is an up-to-date version of #2707.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions