Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
Blaisorblade opened this issue Jan 28, 2019 · 0 comments

Comments

@Blaisorblade
Copy link
Contributor

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.

@abgruszecki abgruszecki changed the title Multiversal equality and type parameters: strictEquality isn't strict enough Strict equality shouldn't allow comparisons between unrelated type parameters Feb 1, 2019
@abgruszecki abgruszecki assigned odersky and unassigned abgruszecki Feb 4, 2019
odersky added a commit to dotty-staging/dotty that referenced this issue Feb 15, 2019
@odersky odersky closed this as completed Feb 15, 2019
odersky added a commit that referenced this issue Feb 15, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants